Repository navigation
[popups] Fix nested hoverable popups - #3798
Conversation
commit: |
Bundle size report
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. |
a20e824 to
fabe248
Compare
Greptile SummaryThis PR successfully implements support for nested preview cards by integrating Key changes:
The implementation correctly addresses the issue where hovering through nested preview cards would close parent cards. The safePolygon handler's logic (lines 147-153 in Confidence Score: 4/5
Important Files Changed
|
| // The handler needs to remain active to detect when mouse leaves to | ||
| // a nested portaled popup. The safePolygon logic checks for open children | ||
| // in the floating tree and prevents closing when appropriate. | ||
| handlerRef.current?.(event); |
There was a problem hiding this comment.
@atomiks I think this fixes the problem.
If we clean the mouse move events when opening the nested popover / preview card, then safePolygon can't properly do its job.
Tbh I don't know the codebase enough yet to be fully confident of the fix.
My experiment of both the nested Popover AND the nested Preview Card now work at least.
And without introducing additional logic that safePolygon should already handle.
There was a problem hiding this comment.
Yeah that looks to be a difference between the two hooks.
useHover
function onFloatingMouseEnter() {
timeout.clear();
clearPointerEvents();
}useHoverFloatingInteraction
function onFloatingMouseEnter(event: MouseEvent) {
openChangeTimeout.clear();
clearPointerEvents();
handlerRef.current?.(event);
cleanupMouseMoveHandler();
}Though the old one still doesn't call handlerRef.current
There was a problem hiding this comment.
I don't get any failing test and the nested popover and preview cards still behavior correctly if I comment the handlerRef.current?.(event); line.
But that's a change that could easily not be covered by any test.
cc @michaldudak since you did the initial useHoverFloatingInteraction implementation
There was a problem hiding this comment.
Looks like the point 3 in Cisco's comment is caused by this handlerRef.current call
Are we fine removing it?
The diff is here: 7a96601
CiscoFran10
left a comment
There was a problem hiding this comment.
@flaviendelangle I found a couple of issues while testing nested previews:
1. Parent trigger does not regain focus when closing with Esc
When pressing Esc, only the child preview returns focus to its trigger.
The parent trigger loses focus and does not regain it.
cursorful-video-1770002383055.mp4
2. Mouse-leave close logic is scoped per preview instead of globally
Each preview popup appears to compute its own “mouse outside” state.
This means the user must move the mouse outside of each preview to close them, even if the cursor is already outside all previews.
Video.sem.titulo.Feito.com.o.Clipchamp.1.mp4
3. Unclear but reproducible odd behavior
Steps to reproduce
- Hover the parent trigger to open the parent preview.
- Hover the child trigger to open the child preview.
- Move the mouse outside of all previews.
- Before the parent preview finishes closing (there seems to be a small close delay), move the mouse back into the parent preview.
- Hover the child trigger again.
Actual result
Both parent and child previews close.
Expected result
The parent preview should remain open, and the child preview should open again normally.
This feels like a race condition between delayed close timers and hover-open logic, but I’m not fully sure.
Video.sem.titulo.Feito.com.o.Clipchamp.2.mp4
|
@CiscoFran10 number 1 is because preview cards don't have focus management (same as tooltip), I would say this is not a concern in practice. For number 2, this is a known issue that Navigation Menu with submenus also has - definitely needs investigating but technically a separate issue. For number 3, not sure on this one, might be the difference between |
|
I'll have a look at the 3rd issue when I have some time then 👍 |
|
Doesn't seem like 7a96601 addressed the third point @CiscoFran10 pointed out as I can still reproduce it in the experiments link. (Edit: actually, it made it worse as the "hover-out" step is no longer needed). Separate issue as well: traversing through the triangle area closes it unexpectedly once you land on the popup. Screen.Recording.2026-02-12.at.11.18.46.am.mov |
There was a problem hiding this comment.
While not perfect this solves the openOnHover regression for Popover.
@CiscoFran10's second and third points still apply, but both of them have a decent workaround by using closeDelay={0} on the triggers, since mousemove events are typically fired for both root and child when moving outside, since the child closes instantly and more than 1 mousemove event is usually fired.
I had a prototype working to solve this robustly, but it adds a lot of code and it's not clear how worth it is over using a 0 close delay.
Atempt to fix #3673
The hardest part was to now close the root Preview Card when hovering through its children Preview Card
Preview: https://deploy-preview-3798--base-ui.netlify.app/experiments/preview-card/nested