Skip to content

Commit

Permalink
also watch ancestors for resize
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglass authored and peterszerzo committed Jul 11, 2024
1 parent 6444eaa commit fd97745
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/journey-manager/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ const Highlight: FunctionComponent<{ element: HTMLElement }> = ({
}) => {
const ref = useRef<HTMLDivElement | null>(null);
const [pos, setPos] = useState<{ x: number; y: number } | null>(null);

const ancestors: Element[] = ((element: HTMLElement) => {
const ancestors: Element[] = [];
while (element.parentNode instanceof HTMLElement) {
ancestors.push(element.parentNode);
element = element.parentNode;
}
return ancestors;
})(element);

useEffect(() => {
if (ref.current != null) {
const highlight = ref.current;
Expand All @@ -403,17 +413,6 @@ const Highlight: FunctionComponent<{ element: HTMLElement }> = ({

const cleanupAutoUpdate = autoUpdate(element, highlight, moveHighlight);
const resizeObserver = new ResizeObserver(moveHighlight);
const ancestors: HTMLElement[] = ((element: HTMLElement) => {
const ancestors: HTMLElement[] = [];
while (
element.parentNode &&
element.parentNode instanceof HTMLElement
) {
ancestors.push(element.parentNode);
element = element.parentNode;
}
return ancestors;
})(element);

ancestors.forEach((ancestor) => {
resizeObserver.observe(ancestor);
Expand Down

0 comments on commit fd97745

Please sign in to comment.