shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
70.11k stars 4.2k forks source link

[bug]: Is there a way to automatically close a Popover if it is not in viewport? #4856

Open kiennt-pivot opened 1 week ago

kiennt-pivot commented 1 week ago

Describe the bug

I am attaching a Popover to a button on my menu bar. I want the Popover to be hidden when it is no longer in the Viewport when scrolled up, but it is scrolled down as well. I have tried using z-indexes on other elements overlaying it but it doesn't work.

Affected component/components

Popover

How to reproduce

1) Create button in navigation 2) Click button to show Popover 3) When scroll, Popover is not in Viewport but it always show

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Google

Before submitting

floris-xlx commented 1 week ago

you have open from the popover, and openOnChange

setting open to false will automatically close it too , throw current Y position and dimensions in an effect and de-render when popover dimensiosn - viewport