fix: compare selector when validating highlight (#18530)
This commit is contained in:
parent
17c8554255
commit
eac5cc98df
|
|
@ -26,7 +26,8 @@ type HighlightEntry = {
|
||||||
tooltipElement?: HTMLElement,
|
tooltipElement?: HTMLElement,
|
||||||
box?: DOMRect,
|
box?: DOMRect,
|
||||||
tooltipTop?: number,
|
tooltipTop?: number,
|
||||||
tooltipLeft?: number
|
tooltipLeft?: number,
|
||||||
|
tooltipText?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Highlight {
|
export class Highlight {
|
||||||
|
|
@ -160,7 +161,7 @@ export class Highlight {
|
||||||
// Code below should trigger one layout and leave with the
|
// Code below should trigger one layout and leave with the
|
||||||
// destroyed layout.
|
// destroyed layout.
|
||||||
|
|
||||||
if (this._highlightIsUpToDate(elements))
|
if (this._highlightIsUpToDate(elements, options.tooltipText))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 1. Destroy the layout
|
// 1. Destroy the layout
|
||||||
|
|
@ -180,7 +181,7 @@ export class Highlight {
|
||||||
tooltipElement.style.left = '0';
|
tooltipElement.style.left = '0';
|
||||||
tooltipElement.style.display = 'flex';
|
tooltipElement.style.display = 'flex';
|
||||||
}
|
}
|
||||||
this._highlightEntries.push({ targetElement: elements[i], tooltipElement, highlightElement });
|
this._highlightEntries.push({ targetElement: elements[i], tooltipElement, highlightElement, tooltipText: options.tooltipText });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Trigger layout while positioning tooltips and computing bounding boxes.
|
// 2. Trigger layout while positioning tooltips and computing bounding boxes.
|
||||||
|
|
@ -232,10 +233,12 @@ export class Highlight {
|
||||||
console.error('Highlight box for test: ' + JSON.stringify({ x: box.x, y: box.y, width: box.width, height: box.height })); // eslint-disable-line no-console
|
console.error('Highlight box for test: ' + JSON.stringify({ x: box.x, y: box.y, width: box.width, height: box.height })); // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private _highlightIsUpToDate(elements: Element[]): boolean {
|
private _highlightIsUpToDate(elements: Element[], tooltipText: string | undefined): boolean {
|
||||||
if (elements.length !== this._highlightEntries.length)
|
if (elements.length !== this._highlightEntries.length)
|
||||||
return false;
|
return false;
|
||||||
for (let i = 0; i < this._highlightEntries.length; ++i) {
|
for (let i = 0; i < this._highlightEntries.length; ++i) {
|
||||||
|
if (tooltipText !== this._highlightEntries[i].tooltipText)
|
||||||
|
return false;
|
||||||
if (elements[i] !== this._highlightEntries[i].targetElement)
|
if (elements[i] !== this._highlightEntries[i].targetElement)
|
||||||
return false;
|
return false;
|
||||||
const oldBox = this._highlightEntries[i].box;
|
const oldBox = this._highlightEntries[i].box;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue