Dialog Focus Trapping With Portals #2299
-
| Assume I have a Select component inside a Dialog component, and both are rendered using portals. What is the best way to handle trapping focus within the modal while still being able to loop through the Select options using arrow keys when the dropdown is open? Seems like if the dropdown is rendered using a portal while inside a Dialog, the navigation accessibility features are disabled since focus is trapped within the Dialog. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
| We'll update the docs shortly. I recommend avoiding using a portal within the modal dialog because it traps focus. Removing the portal should make it work as expected. |
Beta Was this translation helpful? Give feedback.
-
| I think this problem deserves a more dedicated solution, where these portals can be linked together (preferably automatically) so that the code can treat focus not by DOM hierarchy but also take portal hierarchy into account. |
Beta Was this translation helpful? Give feedback.


Seems this may even be already supported in zag's dismissable layers, as @zagjs/dismissable mentions you can nest layers.
https://github.com/chakra-ui/zag/blob/main/packages/utilities/dismissable/README.md