Skip to content

Commit bebf6b6

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
[tooltips] Fix property docs tooltip setting
Bug: 409985196 Fixed: 410515701 Change-Id: Ie7d1cd7bd470faf8814689840c9436cdd64ef09f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6450702 Commit-Queue: Philip Pfaffe <pfaffe@chromium.org> Auto-Submit: Philip Pfaffe <pfaffe@chromium.org> Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org> Commit-Queue: Ergün Erdoğmuş <ergunsh@chromium.org> (cherry picked from commit 5378490) Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6461929 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
1 parent 91f0826 commit bebf6b6

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

front_end/panels/elements/StylePropertyTreeElement.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,4 +1846,34 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
18461846
await openTooltipPromise2;
18471847
assert.notStrictEqual(tooltip, tooltip2);
18481848
});
1849+
1850+
it('shows a property docs tooltip', async () => {
1851+
const webCustomDataStub = sinon.createStubInstance(Elements.WebCustomData.WebCustomData);
1852+
webCustomDataStub.findCssProperty.returns({name: 'color', description: 'test color'});
1853+
sinon.stub(stylesSidebarPane, 'webCustomData').get(() => webCustomDataStub);
1854+
Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').set(false);
1855+
const treeElementWithoutTooltip = getTreeElement('color', 'blue');
1856+
treeElementWithoutTooltip.treeOutline = new LegacyUI.TreeOutline.TreeOutline();
1857+
treeElementWithoutTooltip.updateTitle();
1858+
assert.notExists(treeElementWithoutTooltip.listItemElement.querySelector(
1859+
'devtools-tooltip[jslogcontext="elements.css-property-doc"]'));
1860+
1861+
Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').set(true);
1862+
const treeElementWithTooltip = getTreeElement('color', 'blue');
1863+
treeElementWithTooltip.treeOutline = new LegacyUI.TreeOutline.TreeOutline();
1864+
treeElementWithTooltip.updateTitle();
1865+
renderElementIntoDOM(treeElementWithTooltip.listItemElement);
1866+
const tooltip = treeElementWithTooltip.listItemElement.querySelector(
1867+
'devtools-tooltip[jslogcontext="elements.css-property-doc"]');
1868+
assert.instanceOf(tooltip, Tooltips.Tooltip.Tooltip);
1869+
1870+
tooltip.showPopover();
1871+
assert.isTrue(tooltip.open);
1872+
tooltip.hidePopover();
1873+
assert.isFalse(tooltip.open);
1874+
1875+
Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').set(false);
1876+
tooltip.showPopover();
1877+
assert.isFalse(tooltip.open);
1878+
});
18491879
});

front_end/panels/elements/StylePropertyTreeElement.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
19871987
}
19881988
};
19891989
this.listItemElement.appendChild(tooltip);
1990-
} else if (Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover')) {
1990+
} else if (Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').get()) {
19911991
const cssProperty = this.parentPaneInternal.webCustomData?.findCssProperty(this.name);
19921992

19931993
if (cssProperty) {
@@ -1999,7 +1999,18 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
19991999
id: tooltipId,
20002000
jslogContext: 'elements.css-property-doc',
20012001
});
2002-
tooltip.appendChild(new ElementsComponents.CSSPropertyDocsView.CSSPropertyDocsView(cssProperty));
2002+
tooltip.onbeforetoggle = event => {
2003+
if ((event as ToggleEvent).newState !== 'open') {
2004+
return;
2005+
}
2006+
if (!Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').get()) {
2007+
event.consume(true);
2008+
return;
2009+
}
2010+
2011+
tooltip.removeChildren();
2012+
tooltip.appendChild(new ElementsComponents.CSSPropertyDocsView.CSSPropertyDocsView(cssProperty));
2013+
};
20032014
this.listItemElement.appendChild(tooltip);
20042015
}
20052016
}

0 commit comments

Comments
 (0)