-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Make possible to avoid focusing wrapper #19651
Comments
@dmtrKovalenko Thanks for opening this issue. For context, and for the next person that will have a look at the problem, the current behavior is the result of a tradeoff taken in #14545 to save bundle size. There is likely an opportunity to do better ✨. |
@oliviertassinari I'll look into it. |
Can we take a step back and first identify where we use this focus trap? Seems to me it always traps focus inside a widget where we definitely can focus the widget container. Then the question moves from "how to disable root focus?" to "configure what container TrapFocus should focus!". I say this because the approach in #22062 is fundamentally flawed since it assumes that determining what element is tabbable is something we can do by reading the DOM. However, what elements are tabbable (in sequential focus order) can determined by the user agent (https://html.spec.whatwg.org/multipage/interaction.html#sequentially-focusable). We can ask if an element is in sequential focus order by checking tag names or tabIndex. But returning "No" from that question does not imply that the element is not tabbable. Specifically for the date pickers I recognized the current flaws of the focus trap if it wraps a custom transition component. Sometimes they add wrapper divs, sometimes they don't. We should be able to tell the FocusTrap what the root is e.g. const rootRef = React.createRef();
<FocusTrap rootRef={rootRef}>
<TransitionComponent>
<div data-testid="backdrop">
<div role="dialog" aria-labelledby="..." ref={rootRef} tabIndex={-1} />
</div>
</TransitionComponent/>
</FocusTrap> |
A product I'm working on is being audited by a FAANG company for A11y. Right now, they are dinging us for the extra tab key a user has to hit to cycle the loop. The audit team has labeled this as a "loss of focus" (these come from the sentinels). At some point, we'll have to remediate the issue for our project. With that said, are we still open to a solution that leverages tabbable? i wouldn't mind taking it up |
Summary 💡
Currently TrapFocus component is focusing the modal root element (paper) when we are looping out the controls in the focus.
This is a problem for some kind of dialogs, for example, date-picker. We should avoid focusing on the root element of date picker. Focusing on the root element will only confuse the screenreader because there is no label on the date picker itself.
Anyway, that is not recommended to make "big" elements focusable, because it is not clear which element is focused. For example, this is the default behavior of angular material.
It would be nice to have an option like
disableRootFocus
or something like that that prevents focusing the root element in the dialog.Examples 🌈
Motivation 🔦
From wia-aria modal dialog example guide
The text was updated successfully, but these errors were encountered: