-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TrapFocus] Steals focus from nested portal #15694
Comments
Try a html dialog mayb? |
@alexkirsz The behavior you are describing sounds correct to me. TrapFocus only cares about the DOM structure. The logic isn't applied at the React level. I'm not sure the upcoming I would challenge your problem in the first place. Why do you need to render the input outside of the dialog? Did you consider using a Popover instead of a Popper? This component uses FocusTrap internally. I will handle the case correctly. This makes me think of a #15450 (comment) where the problem is about interoperability. We have a couple of ways to work around the problem. I'm interested in finding the best option. |
@oliviertassinari Thanks for the FocusScope link, I wasn't aware of the ongoing efforts with regards to focus handling in React!
This certainly sounds like it would fix my particular issue! :)
I'm having to apply some custom positioning logic as I want the dropdown to extend to the bottom of the window, but no further. Since I believe both Modal and DialogContent define an FYI, the component currently looks like this: The option list uses |
@alexkirsz Thanks for providing more details. Looking at the visual output. I believe you should be using the Popper component for rendering the list of items, not the input element. So I think that we can close the issue. Regarding the component you have built, it something Material-UI should provide directly. I don't think that we should ask our users to do it every single time. We will work on providing a better solution. If you can share the source, once it meets your expectation, it would be awesome :). |
@oliviertassinari Do you mean replacing the “Select engine” button with the TextField? Thing is, the TextField is only used for filtering between the different options, but its value doesn’t fully represent an option. Hence the “popout” behaviour. |
I'm sorry, I don't follow you. My points were 1. Your codesandbox can be solved with a different approach. 2. Going forward, Material-UI, as a library, wants to support this problem with a built-in component. |
I was referring to the following:
The specifics of the component require the TextField component to be nested within a portal, to achieve the "popout" behaviour wherein you can click on a button and a popper will appear with both a filter input and the filtered option list. So I don't see another way of achieving the same visual output without rendering both components within a portal :/ |
Did you try this Popper demo https://next.material-ui.com/components/autocomplete/#downshift? |
I tried both |
@alexkirsz Interesting. |
Have same problem - form fields doesn't have focus when use it in Popper has opened from Dialog |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If Popper has disablePortal prop, form fields inside it works good |
@verbart Thanks, it looks like the same problem than the author of this issue has. Do we have a better solution than to wait for the release of the
|
@oliviertassinari Thanks, did not know about the "disableEnforceFocus" property. While it best saves the situation. |
Sorry if wrong issue but I think what I'm experiencing is related. We have a Drawer (which renders Modal -> Portal -> TrapFocus). |
Facing a similar issue, any fixes? |
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 aPopper
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 thePopper
is focused (as it should since it'sautoFocus
), then instantly blurred back by theTrapFocus
.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.
Duplicates
The text was updated successfully, but these errors were encountered: