Skip to content

Commit

Permalink
Recalculate popover position when resized while open
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Jan 20, 2025
1 parent 0255544 commit 8382061
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/feedback/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ function usePopoverPositioning(

// First of all, open popover if it's using the native API, otherwise its
// size is 0x0 and positioning calculations won't work.
const popover = popoverRef.current;
const popover = popoverRef.current!;
if (asNativePopover) {
popover?.togglePopover(true);
popover.togglePopover(true);
}

const cleanup = adjustPopoverPositioning();
Expand All @@ -151,12 +151,18 @@ function usePopoverPositioning(
capture: true,
});

// Readjust popover positioning if its resized, in case it dropped-up, and
// it needs to be moved down
const observer = new ResizeObserver(adjustPopoverPositioning);
observer.observe(popover);

return () => {
if (asNativePopover) {
popover?.togglePopover(false);
}
cleanup();
listeners.removeAll();
observer.disconnect();
};
}, [adjustPopoverPositioning, asNativePopover, popoverOpen, popoverRef]);
}
Expand Down

0 comments on commit 8382061

Please sign in to comment.