-
Notifications
You must be signed in to change notification settings - Fork 63
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
Tabbing to a phantom element? #268
Comments
Hi, @suspiration , thanks for reaching out! I check it out and the problem seems to be the fragment you have as the child of the FocusTrap. The "phantom" element is the body itself, which gets focused after the close button, so the trap is effectively not working in this case. I haven't debugged it, but I think you end-up in the silent "else" clause of this IF statement, which means the focus trap doesn't even get created. If you change your fragment for a Fragments are special, and FocusTrap expects a single child element. Clearly, the fragment satisfies all the conditions of a single child in the And then it would explain why https://github.com/focus-trap/focus-trap-react/blob/master/src/focus-trap-react.js#L75 ends-up with First thought is FocusTrap could throw at line 158 if Otherwise, FocusTrap does support multiple container elements, but that's not what we have here inside the fragment. We just have multiple "leaf" children. Nothing to build a focus trap around. So we'd have to maybe look up for the nearest parent and use that as the container, but I'm not sure what consequences there may be out in the wild. I'm leaning on the side of throwing an exception to point out that fragments aren't supported. If you have any thoughts, please share! |
Thanks @stefcameron that worked! I think throwing an error and adding in documentation that fragments cannot be used as a single child element would be helpful for other users who run into the same issue. I'm going to leave this open for you to add the changes against, unless you want it closed. |
My pleasure!
👍 |
Fixes #268 Right now, this silently "fails" and appears to work, but it's actually not working because the trap isn't activated, because it couldn't find a DOM element for the Fragment. This change throws an error if a child is given and it's a Fragment.
Fixing with #269 |
Fixes #268 Right now, this silently "fails" and appears to work, but it's actually not working because the trap isn't activated, because it couldn't find a DOM element for the Fragment. This change throws an error if a child is given and it's a Fragment.
I have this codesandbox: https://codesandbox.io/s/material-ui-accessibility-workaround-forked-gd7ok?file=/src/App.tsx
Once you've opened the dialog, there is a textfield and a button. I set FocusTrap inside the dialog around the textfield and button. When I tab between the elements, it goes to the textfield, then button, then to some phantom element before wrapping back to textfield. Any idea? Thanks in advanced!
The text was updated successfully, but these errors were encountered: