Skip to content

Commit 9d445e2

Browse files
SignezSharglutDev
authored andcommitted
front: prevent popover from following the viewport
In OSRD, we use fields inside of wrappers that scrolls themselves. Using popovers, we punch these divs through all those wrappers into the top-layer; this prevents the computation from actually positionning the div at the right place. This should be reverted/removed altogether with this hook as soon as we have CSS native anchoring, as it won't have this kind of problems at all. Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
1 parent edf491e commit 9d445e2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

front/ui/ui-core/src/hooks/usePopoverPosition.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ export const usePopoverPosition = (
3232
}, [inputRef, popoverRef, verticalOffset]);
3333

3434
useEffect(() => {
35-
const handleResize = () => calculatePosition();
36-
window.addEventListener('resize', handleResize);
37-
return () => window.removeEventListener('resize', handleResize);
35+
const handleResizeScroll = () => calculatePosition();
36+
window.addEventListener('resize', handleResizeScroll);
37+
// TODO: Get rid of this as soon as we can, using CSS native anchoring
38+
window.addEventListener('scroll', handleResizeScroll, true);
39+
return () => {
40+
window.removeEventListener('resize', handleResizeScroll);
41+
window.removeEventListener('scroll', handleResizeScroll, true);
42+
};
3843
}, [calculatePosition]);
3944

4045
return { popoverPosition, calculatePosition };

0 commit comments

Comments
 (0)