DEV Community

Discussion on: ✨ Inclusive components: making modals accessible 🧑‍🦯

Collapse
 
plweil profile image
Peter Weil

This is much needed!

"When a user clicks the ‘Open modal’ button then, we need to actively set their focus to the modal with JavaScript, and if they ever tab outside the modal, we need to set the focus back on the modal."

To ensure that no one, including screen reader users, can get outside the modal, I suggest using the inert polyfill, which makes everything in the DOM unclickable and unfocusable.

github.com/GoogleChrome/inert-poly...

As for the initial focus, you should use the specs as an initial guide but do testing for your particular scenario. And the same goes for where you put the focus after closing the modal dialog.