fix(FloatingFocusManager): check for blurring to nested elements inside the React tree without FloatingTree
#3318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3060
When the nested floating element isn't nested inside the parent's portal element (changing the
root
onFloatingPortal
to escape this behavior), it closes unexpectedly becausefocusout
is triggered and the handler doesn't have knowledge of the React tree, only the DOM tree.This PR changes this by using the same capture phase technique to let the handler know it's inside the React tree, to avoid needing to setup
FloatingTree
. This is how outside press is handled already.One caveat is that it requires
useDismiss
to be used in conjunction withFloatingFocusManager
to work becauseFloatingFocusManager
can't assign React props. (It seems thecloseOnFocusOut
logic inFloatingFocusManager
could better live insideuseDismiss
instead - a possible refinement for v1).Solving nested
useHover
still requiresFloatingTree
at this time, but I need to investigate how that could work.