Skip to content

Commit 200d916

Browse files
committed
relocate target highlighting when window is resized
1 parent e9474a2 commit 200d916

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/components/VisualTour/VisualTour.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,29 @@ const StepPopover = ({ highlightedElement, step, titleOption, actionButtons }: S
285285

286286
const backdropRef = React.useCallback(
287287
(backdrop: HTMLDivElement | null) => {
288-
if (backdrop) {
288+
const highlightStencil = () => {
289289
const targetRect = highlightedElement.getBoundingClientRect();
290-
backdrop.style.left = `calc(${
290+
backdrop!.style.left = `calc(${
291291
targetRect.left + window.scrollX + "px"
292292
} - var(--${eccgui}-visual-tour-focus-padding))`;
293-
backdrop.style.top = `calc(${
293+
backdrop!.style.top = `calc(${
294294
targetRect.top + window.scrollY + "px"
295295
} - var(--${eccgui}-visual-tour-focus-padding))`;
296-
backdrop.style.width = `calc(${
296+
backdrop!.style.width = `calc(${
297297
targetRect.width + "px"
298298
} + 2 * var(--${eccgui}-visual-tour-focus-padding))`;
299-
backdrop.style.height = `calc(${
299+
backdrop!.style.height = `calc(${
300300
targetRect.height + "px"
301301
} + 2 * var(--${eccgui}-visual-tour-focus-padding))`;
302+
};
303+
if (backdrop) {
304+
highlightStencil();
305+
window.addEventListener("resize", highlightStencil);
306+
return () => {
307+
window.removeEventListener("resize", highlightStencil);
308+
};
302309
}
310+
return;
303311
},
304312
[highlightedElement]
305313
);

0 commit comments

Comments
 (0)