Repository navigation
[popups] Fix nested hoverable popups - #4206
Conversation
This fixes two issues: 1. All popups suddenly closing when entering a child popup, after having briefly moved outside of the parent popup. Similarly, all popups closing upon entering the child when the parent is defaultOpen. 2. Popups not closing simultaneously when moving out of a child popup.
commit: |
Bundle size reportℹ️ Using snapshot from parent commit 0c5a1d5 (fallback from merge base 047eca4).
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The Screen.Recording.2026-02-27.at.2.36.33.pm.movIt should close once you stop scrolling (does on master, here it doesn't). It does complicate nested popups though. |
This is needed to handle cases where the mouse leaves the element due to scrolling (no mousemove events get fired). Delay closing of parent popups (when the last child is closed) to the next tick, so that we get to process a mouseenter event that follows a mouseleave. This matters for popups with closeDelay=0, where a child is technically closed _before_ the mouse re-enters the parent.
|
I see. I added back an invocation of |
|
Findings (Codex)
|
79666fc to
5614494
Compare
|
Those two should be fixed now. |
atomiks
left a comment
There was a problem hiding this comment.
Nice, thanks for the contribution @dmitri-gb! Looks to have fixed all the issues correctly and I couldn't find any regressions
This fixes two issues that were not fixed in #3798.
All popups suddenly closing when entering a child popup, after having briefly moved outside of the parent popup. Or similarly, all popups closing upon entering the child when the parent is
defaultOpen.Popups not closing simultaneously when moving out of a child popup.
Videos of both issues can be seen in a comment on the previous PR.
I removed some code that seemed redundant. There was no reason to have two different mouseleave listeners that did very similar things. And the safePolygon "handler" is no longer disposed of so eagerly. It stays "alive" for as long as the popup is open.
I also made changes so that nested popups would continue to work even when no safePolygon "handler" was available (
useHoverReferenceInteractioncan just as well be called withouthandleClose: safePolygon()). The parent-child relationship check is just ~3 lines of code insafePolygon.ts, so there's really no need to exclusively rely on the "handler" for this logic.Lastly, a small side-note — both of these bugs are inherited from
@floating-ui/react(exact same behaviour is reproduced with simple floating-ui code), and so the olderuseHoverhook (which I didn't touch) has these issues too.