Skip to content

Commit cb1e1ed

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Automatically reopen tooltips on rerender
When a tooltip gets detached without being closed and then gets replaced by a tooltip with the same id, the new tooltip is automatically reopend once connected. This addresses an issue in the styles tab where property values are rerendered entirely on changes. Fixed: 404720158 Change-Id: I9e0f40f42898343faf112dc92127463fc7cab7f8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6387117 Auto-Submit: Philip Pfaffe <[email protected]> Commit-Queue: Philip Pfaffe <[email protected]> Reviewed-by: Kateryna Prokopenko <[email protected]>
1 parent 0a15a0f commit cb1e1ed

File tree

8 files changed

+221
-106
lines changed

8 files changed

+221
-106
lines changed

front_end/panels/elements/CSSValueTraceView.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ function getLineText(line: Node[][]) {
8484
renderElementIntoDOM(node, {allowMultipleChildren: true});
8585
}
8686
}
87-
return line.map(
87+
const text = line.map(
8888
nodes => nodes
8989
.map(
9090
node =>
9191
(node instanceof HTMLElement ? node.innerText :
9292
(node.nodeType === Node.TEXT_NODE ? node.textContent : '')))
9393
.join());
94+
for (const node of line.flat()) {
95+
if (node instanceof HTMLElement) {
96+
node.remove();
97+
}
98+
}
99+
return text;
94100
}
95101

96102
describeWithMockConnection('CSSValueTraceView', () => {

front_end/panels/elements/StylePropertiesSection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ export class StylePropertiesSection {
163163
#customHeaderText: string|undefined;
164164
readonly #specificityTooltips: HTMLSpanElement;
165165
static #nextSpecificityTooltipId = 0;
166+
static #nextSectionTooltipIdPrefix = 0;
167+
readonly sectionTooltipIdPrefix = StylePropertiesSection.#nextSectionTooltipIdPrefix++;
166168

167169
constructor(
168170
parentPane: StylesSidebarPane, matchedStyles: SDK.CSSMatchedStyles.CSSMatchedStyles,

front_end/panels/elements/StylePropertyTreeElement.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
getMatchedStylesWithBlankRule,
1818
} from '../../testing/StyleHelpers.js';
1919
import * as CodeMirror from '../../third_party/codemirror.next/codemirror.next.js';
20-
import type * as Tooltips from '../../ui/components/tooltips/tooltips.js';
20+
import * as Tooltips from '../../ui/components/tooltips/tooltips.js';
2121
import * as InlineEditor from '../../ui/legacy/components/inline_editor/inline_editor.js';
2222
import * as LegacyUI from '../../ui/legacy/legacy.js';
2323

@@ -675,11 +675,12 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
675675
const cssVarSwatch = linkSwatch.parentElement;
676676
assert.exists(cssVarSwatch);
677677
assert.exists(stylePropertyTreeElement.valueElement);
678-
renderElementIntoDOM(stylePropertyTreeElement.valueElement, {allowMultipleChildren: true});
678+
renderElementIntoDOM(stylePropertyTreeElement.valueElement);
679679

680680
assert.strictEqual(stylePropertyTreeElement.valueElement.innerText, `var(${varName}, var(--blue))`);
681681
assert.strictEqual(linkSwatch?.innerText, varName);
682682
assert.strictEqual(cssVarSwatch.innerText, `var(${varName}, var(--blue))`);
683+
stylePropertyTreeElement.valueElement.remove();
683684
}
684685
});
685686

@@ -1437,7 +1438,7 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
14371438
const swatch = stylePropertyTreeElement.valueElement?.querySelector('devtools-color-swatch');
14381439
assert.exists(swatch);
14391440
assert.exists(stylePropertyTreeElement.valueElement);
1440-
renderElementIntoDOM(stylePropertyTreeElement.valueElement, {allowMultipleChildren: true});
1441+
renderElementIntoDOM(stylePropertyTreeElement.valueElement);
14411442
assert.strictEqual(swatch?.innerText, lightDark);
14421443
const activeColor = colorScheme === SDK.CSSModel.ColorScheme.LIGHT ? lightText : darkText;
14431444
assert.strictEqual(
@@ -1449,6 +1450,7 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
14491450
const inactive = colorScheme === SDK.CSSModel.ColorScheme.LIGHT ? dark : light;
14501451
assert.isTrue(inactive.parentElement?.classList.contains('inactive-value'));
14511452
assert.isFalse(active.parentElement?.classList.contains('inactive-value'));
1453+
stylePropertyTreeElement.valueElement.remove();
14521454
}
14531455

14541456
await check(SDK.CSSModel.ColorScheme.LIGHT, 'red', 'blue');
@@ -1694,11 +1696,12 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
16941696
const stylePropertyTreeElement = getTreeElement('width', property);
16951697
stylePropertyTreeElement.updateTitle();
16961698
assert.exists(stylePropertyTreeElement.valueElement);
1697-
renderElementIntoDOM(stylePropertyTreeElement.valueElement, {allowMultipleChildren: true});
1699+
renderElementIntoDOM(stylePropertyTreeElement.valueElement);
16981700
const tooltip = stylePropertyTreeElement.valueElement.querySelector('devtools-tooltip');
16991701
assert.exists(tooltip);
17001702
const widget = tooltip.firstElementChild && LegacyUI.Widget.Widget.get(tooltip.firstElementChild);
17011703
assert.instanceOf(widget, Elements.CSSValueTraceView.CSSValueTraceView);
1704+
stylePropertyTreeElement.valueElement.remove();
17021705
}
17031706
});
17041707

@@ -1819,4 +1822,25 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
18191822
]);
18201823
});
18211824
});
1825+
1826+
it('reopens open tooltips on updates', async () => {
1827+
const openTooltipStub = sinon.stub(Tooltips.Tooltip.Tooltip.prototype, 'showPopover');
1828+
const openTooltipPromise1 = new Promise<void>(r => openTooltipStub.callsFake(r));
1829+
const stylePropertyTreeElement = getTreeElement('color', 'color-mix(in srgb, red, blue)');
1830+
stylePropertyTreeElement.updateTitle();
1831+
const tooltip = stylePropertyTreeElement.valueElement?.querySelector('devtools-tooltip');
1832+
assert.exists(tooltip);
1833+
renderElementIntoDOM(tooltip);
1834+
tooltip.showTooltip();
1835+
await openTooltipPromise1;
1836+
tooltip.remove();
1837+
1838+
const openTooltipPromise2 = new Promise<void>(r => openTooltipStub.callsFake(r));
1839+
stylePropertyTreeElement.updateTitle();
1840+
const tooltip2 = stylePropertyTreeElement.valueElement?.querySelector('devtools-tooltip');
1841+
assert.exists(tooltip2);
1842+
renderElementIntoDOM(tooltip2);
1843+
await openTooltipPromise2;
1844+
assert.notStrictEqual(tooltip, tooltip2);
1845+
});
18221846
});

0 commit comments

Comments
 (0)