Opening button doesn't get focus when modal closes in iOS with VoiceOver
backwardok opened this issue · 3 comments
Issue
Steps to reproduce:
- Turn on VO on an iOS device (doesn't seem to matter what version, even the latest version has this issue)
- Go to the main demo page and navigate to the Inline Attribute Configuration example
- Click the Show Modaal button to open the modal
- Tap the screen to get focus to go to the modal (there's a separate issue where the modal doesn't get focus)
- Navigate via swiping to the close button of the modal (at the end)
- Activate the close button
What's expected:
VO focus moves back to the Show Modaal button
What happens:
VO focus is at the end of the page (where the modal previously existed)
What's going on
MDN's activeElement documentation mentions that on a Mac, this may only work with text inputs. I found that this is only true on iOS and not on the Mac. If you are on a button that's focused and you query for activeElement
, it doesn't return anything.
As commented in #99, we seem to be running into is a random result in the 'return to last focus state' where VoiceOver, if it can't find/remember the state for whatever reason, will default to a focusable element nearest the last press being the close button of the modal.
What JavaScript we've tested so far doesn't seem to have much difference as VoiceOver will make its own decisions on where to go and ignore what we're asking it to do.
In short, needs more work but the issue is understood. Contribution on this from anyone is very welcome.
For this one, you likely need to pass in a reference to the opening element (or actually keep track of what opened it when it triggers the modal) to explicitly focus that element (instead of activeElement
) since iOS Safari doesn't seem to track <button>
s as active.
Thanks @backwardok - we already do keep track of the original element at the point the modal is triggered to open, only it hasn't been used by VoiceOver correctly or as expected. The replies to #99 have given us a good base and reference point to work from, so we expect to have updates to this task as well rolled into that. Thanks again!