Skip to content

Commit 5378490

Browse files
pfaffeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[tooltips] Fix property docs tooltip setting
Fixed: 409985196 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>
1 parent 42ca9df commit 5378490

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

front_end/panels/elements/StylePropertyTreeElement.test.ts

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

front_end/panels/elements/StylePropertyTreeElement.ts

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

19981998
if (cssProperty) {
@@ -2004,7 +2004,18 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
20042004
id: tooltipId,
20052005
jslogContext: 'elements.css-property-doc',
20062006
});
2007-
tooltip.appendChild(new ElementsComponents.CSSPropertyDocsView.CSSPropertyDocsView(cssProperty));
2007+
tooltip.onbeforetoggle = event => {
2008+
if ((event as ToggleEvent).newState !== 'open') {
2009+
return;
2010+
}
2011+
if (!Common.Settings.Settings.instance().moduleSetting('show-css-property-documentation-on-hover').get()) {
2012+
event.consume(true);
2013+
return;
2014+
}
2015+
2016+
tooltip.removeChildren();
2017+
tooltip.appendChild(new ElementsComponents.CSSPropertyDocsView.CSSPropertyDocsView(cssProperty));
2018+
};
20082019
this.listItemElement.appendChild(tooltip);
20092020
}
20102021
}

0 commit comments

Comments
 (0)