[TrapFocus] Steals focus from nested portal
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior š¤
TrapFocus
ensures focus is kept on elements within its React element spanning tree.
Current Behavior šÆ
Since TrapFocus
keeps the focus on elements within its DOM hierarchy, focusable elements within its React hierarchy but outside its DOM hierarchy (e.g. inside of a Popper
or a portal) canāt be focused.
Steps to Reproduce š¹
Example: https://codesandbox.io/s/llv0m7r5jq
Click on the [Open Dialog] button, then on the [Open Popper] button. In the console, youāll see that the TextField
within the Popper
is focused (as it should since itās autoFocus
), then instantly blurred back by the TrapFocus
.
Context š¦
Iām building an autocomplete component with a āpopoutā behaviour similar to the one demonstrated at the bottom of react-selectās Advanced doc.
The autocomplete button itself is rendered within a dialog, and Iām using a popper to display the text input and options. Right now Iām disabling the portal behaviour so itās kept inside the modalās DOM hierarchy, but this causes issues with the selectās option list overflowing from the modal. My final solution seems very hacky and prone to unexpected failure, so Iād love this to be handled by MUI itself.
Your Environment š
For the stack, see codesandbox.
Tech | Version |
---|---|
Browser | Chrome 74.0.3729.131 |
Duplicates
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:19 (12 by maintainers)
@verbart Thanks, it looks like the same problem than the author of this issue has.
disabledPortal
allows to partially work around the problem, as well asdisableEnforceFocus
.Do we have a better solution than to wait for the release of the
<FocusScope>
component?https://github.com/facebook/react/pull/15487
@emirotin That sounds like #17497