-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow modal dialogs to trap focus, avoiding tabbing to the URL bar #8339
Comments
I think this issue is worth discussing, as anecdotally I both know people who appreciate that keyboard focus can easily go to the browser chrome when a modal dialog is open, as well as those that would rather it did not. However, the issue as filed is not entirely accurate in what is required by WCAG, let alone ARIA.
Both the APG modal dialog and the WCAG understanding doc were written long before the So with all that said I want to repeat that I do think this is a conversation worth having and it did come up in conversations related to #7707. However, it is not accurate to say that the current behavior doesn't meet WCAG. Though it is understandable why people would expect this behavior, as trapping focus within a dialog has long been the most practical guidance for developers who were building their own custom dialogs. |
Just dropping in to confirm what @scottaohara mentions above: WCAG does not normatively define how modal dialogs should or shouldn't behave in terms of focus. WCAG gives examples in understanding documents, but these are, by their nature, non-normative (so treat them more or less as best practice suggestions, and not exhaustive, and pretty much as a SHOULD) Another example, for instance, is in the understanding for 2.4.3 Focus Order [edit: ah, just seen that Scott also mentioned it in his edited comment above] https://www.w3.org/WAI/WCAG21/Understanding/focus-order.html
But again, if a dialog does not do this for some reason, it's not immediately a hard failure (unless there's no logical rationale for it, and it does random things like allowing focus to stroll back into the underlying page). But there's certainly nuance, subjectivity, context-specific considerations. |
HTMLDialog.prototype.showModal()
focus trapping to WCAG 2.1
I've renamed this issue to reflect the above comments. Thanks @scottaohara and @patrickhlauke for setting the record straight. |
Thanks all for the excellent explanations for someone that doesn't have a ton of experience in this field. They are all really helpful ❤️ Aren't the browsers' UI controls always accessible to users via a keyboard shortcut? I'd imagine that using those instead of jumping to the browser controls at the end of a modal dialog would be better. Still, I'd defer to experts on accessibility and screenreader users over that 😄 Does the Pop-Up API maybe solve all of this? |
Using F6 can allow someone to jump to either the browser tabs or address bar - depending on the browser. Command + L is how to do it with Safari. Again, anecdotally what's better will come down to the individual.
It does not. It's not meant to be used for modals. |
From a purely personal perspective, I like that I can "escape" a page where a modal dialog hasn't quite been marked up correctly by tabbing out to the address bar. I really dislike it when the focus is trapped in a specific area. With ARIA menus, for example, my JAWS focus can get trapped within the menu until I make a selection, when sometimes I just want to back out without doing anything. Makes me feel as though I'm caught in a mouse trap :-( |
In this case it may not be the experts we should be listening to 😊 From the point of view of someone who doesn't know what a modal dialog is or how it's implemented, a dialog is to all intents and purposes another page. In the page context you can choose to Tab out of the bottom and around the browser chrome, you can use a keyboard command to move straight to the address bar or open a particular menu, you can close the tab, and so on. This gives people a choice about how, why, and what they do to escape out of the context. It seems logical (to me at least) for the same options to be available to people when in a dialog context instead of a page context. For someone who doesn't recognise or understand the difference, I imagine it must be frustrating to discover that your usual method may no longer work. |
This comment comes from W3C's Accessible Platform Architectures (APA) WG. A personal tl;dr from me is that I think everyone's in alignment on this. Input came from all of us; thanks to @niklasegger for drafting this. We addressed this question in the course of several APA meetings and came to the conclusion that the current behavior of the native dialog element should be kept as it is. So, that you can tab from the dialog to the browser functionalities. We see especially the benefit that keyboard users can, for example, open a new tab to look something important up or to change a browser setting this way. At the same time, the dialog element thus provides an additional natural escape mechanism (i.e. moving to the address bar) in, for example, kiosk situations where the user cannot use other standard keyboard shortcuts. In addition, we also see how this can confuse some developers, as prior to the native dialog it was common when implementing a custom dialog component to really trap the focus. For this reason, we will also get in contact with the APG group to talk about a change in the guide for the dialog (modal) pattern. We think an additional note is useful, pointing out that when using the native dialog element, tabbing to browser functionality is normal and wanted, and does not need to be "fixed" by one's own hand. Since for many developers APG's guides are the go-to resource for implementing accessible components, hopefully this will prevent more confusion in the future. |
It sounds like most people are in agreement that the current functionality is correct so I think we can just close this. Maybe there is a opportunity to make this position more clear in the spec? In any case I really appreciate everyones time to make comments and share their thoughts ❤️ I haven't done a lot of spec work and it can be a bit daunting but everyone has been super nice. |
Does anyone know, whether this documentation will be updated? https://www.w3.org/WAI/WCAG21/Understanding/no-keyboard-trap.html
|
@grzegorzkrzyminski the doc is still accurate for custom dialogs. Might help if you file an issue against wcag for the update to be considered. |
@scottaohara I see. From "outside" it's a bit tricky - It's hard to say, that this particular recommendation might be related to custom modal only. After all, someone can use it as a reference that a native element doesn't work correctly according to this documentation. The consequences are, that the dialog behavior might be overridden with custom-js logic by a developer, even if it's not needed. |
@grzegorzkrzyminski again, i'd suggest opening an issue against wcag since this is discussion about their content. |
Hello!
We'd like to make a change to the spec to make sure that user agents focus trap the user with in a
HTMLDialog.prototype.showModal()
in order to be more closely aligned with WCAG2.1:Some comments from a previous discussion in https://crbug.com/1363100:
@koddsson & @keithamus
@domenic
@koddsson & @keithamus
Maybe related: #2171 and #7707
The text was updated successfully, but these errors were encountered: