-
Notifications
You must be signed in to change notification settings - Fork 60
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
Autofocus in modals forcing screenreaders to the end of the modal #854
Comments
While I agree it would be nice to be able to disable the autofocus in a modal when desired, one workaround may be to add:
at the top of your form (or in whatever position will best serve your modal). |
For now we are going to add support for adding |
I've investigated this and at the moment the focus is actually coming from the native Dialog element. It by default focuses the first focusable element in the dialog. I can't find a simple way to disable the autofocus for the Dialog element. Instead there are a bunch of solutions similar to @jeffchown's which suggest to add a hidden input at the top of the Dialog which is focusable. @stuininga1 do you have any experience with screen readers and the native Dialog element or any suggestions on how best to handle it? |
@joshhanley I've run into something similar, I see MDN says you could add autofocus to the dialog itself to effectively disable. Does that mean we could actually get a https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
|
@jradtilbrook thanks for the link! I just tested adding autofocus to the dialog itself, but it didn't seem to do anything. If you can give me an example of that working, I'd be happy to see if I can get working with Flux's modal. |
Ah yes I initially implemented it in firefox and it worked. But now trying it in chrome, it does not 😭 Is that the browser you tried? |
@jradtilbrook ah bummer 😕 that would have been great if it worked across all browsers. |
Flux version
1.0.23
Livewire version
3.5.12
What is the problem?
When you use a Flux modal, it autofocuses whatever is actionable (like an input or a button) within the modal. This makes sense for a sighted user who can read the modal's content then proceed to interact with whatever actionable element is focused. However for a screenreader, unless the actionable element is the absolute first one in the modal the autofocus skips them over the regular flow in the modal. This means that in order to fully read a modal screenreaders have to scan backwards from the actionable element to any text elements (like headings or paragraphs) then navigate forward again which isn't very accessible since people with vision impairments can't see that there's more content to navigate to.
Originally reported in this discussion thread: #796 (reply in thread)
Code snippets
On the site I'm trying to meet accessibility on, I have modals with a heading, text, then an action button at the bottom. However because of the autofocus functionality the user is automatically being forced to the bottom of my modal. You should be able to recreate this with any Flux modal with both text elements and actionable items, but since this ask for how to reproduce it, this is the exact code I've been using when testing this issue:
I've customized the modal component to allow me to have my close action as a button instead of a standard x (only change is to the close button section)
Then the modal I'm actually testing with looks like so:
My actual modal looks like this:

How do you expect it to work?
I would expect that the modal would allow the screenreader to focus on the first element first, then move through the modal in normal document flow instead of being autofocused and forced to skip around in the document flow in order to get all of the content out of a modal. Whether this is the ability to turn off autofocus in modals or choose which element gets focus first, either would work to allow developers to create accessible modals!
Please confirm (incomplete submissions will not be addressed)
The text was updated successfully, but these errors were encountered: