useFocusOutside: do not fire callback when focusing on an iframe inside the wrapper #45349
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.
What?
Requires #45317
Related to #40912
Try to fix an issue with
useFocusOutside
, where the callback would be fired when interacting with aniframe
(and its contents) inside the wrapper element.Why?
The problem is related to how the hook works and how those principles don't function well with an
iframe
: the hook, in fact, cancels the timeout that would cause the callback to fire if afocus
event if fired rapidly after ablur
event (both events need to happed inside the wrapper element).The
iframe
element doesn't seem to fire onfocus
andblur
events, therefore breaking theuseFocusOutside
logic.How?
So far, I managed to make some progress by:
tabindex={-1}
to theiframe
element, which allows it to be consistently identified as the active elementcontains
the active element (this is a way to get around the fact that theiframe
doesn't firefocus
events)The issue I'm still facing is that, since the
iframe
doesn't fire theblur
event, the callback doesn't fire as reliably as it should — this can be tested in the extra Storybook example forModal
that I've added in this PR:Testing Instructions
TBD
(It would be great to add extra unit tests too, so far I've attempted to write one but it's not final yet)
Screenshots or screencast