Skip to content

Commit

Permalink
fix(core): add scroll event listener for AnnotationToolbarPopover ref…
Browse files Browse the repository at this point in the history
…erenceBoundary
  • Loading branch information
ninaandal committed Dec 20, 2023
1 parent bb0377a commit a48f9a3
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ export function AnnotationToolbarPopover(props: AnnotationToolbarPopoverProps) {
}, [])

useEffect(() => {
const sel = window.getSelection()
if (sel && sel.rangeCount > 0) {
rangeRef.current = sel.getRangeAt(0)
}
}, [popoverOpen])

useEffect(() => {
//Attach and detach scroll event listener for popover to follow the current reference boundary
if (popoverOpen && referenceBoundary) {
referenceBoundary.addEventListener('scroll', handleScroll)
return () => referenceBoundary.removeEventListener('scroll', handleScroll)
}

if (!popoverOpen) {
return undefined
}
Expand Down

0 comments on commit a48f9a3

Please sign in to comment.