Last active
August 21, 2018 20:49
-
-
Save everdimension/878d41986837a0f7f5ab768f9580090c to your computer and use it in GitHub Desktop.
A proper way to create an accessible modal dialog element (a11y). This gist is only about the wrapper element, the links in the comment describe all necessary steps in detail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
A tabindex="-1" allows an element to receive programmatic focus. | |
This is useful a modal dialog window: when opened, focus should be set to the dialog so a screen reader | |
will begin reading and the keyboard will be able to navigate within the dialog. | |
Because the dialog (probably a <div> element) is not focusable by default, assigning it tabindex="-1" | |
allows scripting to set focus to it when it is presented | |
Resources: | |
https://www.w3.org/WAI/GL/wiki/Using_ARIA_role%3Ddialog_to_implement_a_modal_dialog_box#Note_on_focus_management | |
https://webaim.org/techniques/keyboard/tabindex | |
--> | |
<div | |
tabindex="-1" | |
role="dialog" | |
aria-labelledby="myDialog" | |
><!-- content --></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment