Skip to content

Commit

Permalink
Fix scroll for custom offset parent/scroll
Browse files Browse the repository at this point in the history
- add delayed popper update to fix placement
  • Loading branch information
gilbarbara committed Dec 14, 2023
1 parent 5c22fd9 commit 5d0d150
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ class Joyride extends React.Component<Props, State> {

/* istanbul ignore else */
if (status === STATUS.RUNNING) {
scrollTo(scrollY, { element: scrollParent as Element, duration: scrollDuration });
scrollTo(scrollY, { element: scrollParent as Element, duration: scrollDuration }).then(
() => {
setTimeout(() => {
this.store.getPopper('tooltip')?.instance.update();
}, 10);
},
);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/modules/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function hasCustomScrollParent(element: HTMLElement | null, skipFix: bool

const parent = getScrollParent(element, skipFix);

return !parent.isSameNode(scrollDocument());
return parent ? !parent.isSameNode(scrollDocument()) : false;
}

/**
Expand Down Expand Up @@ -188,7 +188,11 @@ export function getElementPosition(
parentTop = parent.scrollTop;
}

const top = (elementRect?.top ?? 0) + (!hasScrollParent && !hasPosition(element) ? parentTop : 0);
let top = (elementRect?.top ?? 0) + (!hasScrollParent && !hasPosition(element) ? parentTop : 0);

if (!parent.isSameNode(scrollDocument())) {
top += scrollDocument().scrollTop;
}

return Math.floor(top - offset);
}
Expand Down

0 comments on commit 5d0d150

Please sign in to comment.