third_party/aria-practices/src/content/patterns/dialog-modal/examples/dialog.html
Following is an example implementation of the Dialog (Modal) Pattern. The below Add Delivery Address button opens a modal dialog that contains two buttons that open other dialogs. The accessibility features section explains the rationale for initial focus placement and use of aria-describedby in each dialog.
Similar examples include:
Add Delivery Address
Street:
City:
State:
Zip:
Special instructions: For example, gate code or other information to help the driver find you
Verify AddressAddCancel
This is just a demonstration. If it were a real application, it would provide a message telling whether the entered address is valid.
For demonstration purposes, this dialog has a lot of text. It demonstrates a scenario where:
There are several ways to resolve this issue:
Please DO NOT make the element with role dialog focusable!
In this dialog, the first paragraph has tabindex=-1. The first paragraph is also contained inside the element that provides the dialog description, i.e., the element that is referenced by aria-describedby. With some screen readers, this may have one negative but relatively insignificant side effect when the dialog opens -- the first paragraph may be announced twice. Nonetheless, making the first paragraph focusable and setting the initial focus on it is the most broadly accessible option.
link to helpaccepting an alternative formClose
The address you provided has been added to your list of delivery addresses. It is ready for immediate use. If you wish to remove it, you can do so from your profile.
OK
You activated a fake link or button that goes nowhere! The link or button is present for demonstration purposes only.
Close
To make the content easier to read when displayed on small screens, the dialog fills 100% of the screen. Completely covering the background window also hides background movement that occurs on some mobile devices when scrolling content inside the dialog.
Focus and accessible descriptions are set based on the content of each dialog.
Add Delivery Address dialog (id=dialog1):
- Initial focus is set on the first input, which is the first focusable element.
- The dialog does not need aria-describedby since there is no static text that describes it.
- When the dialog closes as a result of the Cancel action, the user's point of regard is maintained by returning focus to the Add Delivery Address button.
- When the dialog closes as a result of the Add action and the Address Added dialog replaces the Add Delivery Address dialog, the Add Delivery Address dialog passes a reference to the Add Delivery Address button to the Address Added dialog so that it can maintain the user's point of regard when it closes.
Verification Result dialog (id=dialog2):
- Initial focus is set on the first paragraph because the first interactive element is at the bottom, which is out of view due to the length of the text.
- To support screen reader user awareness of the dialog text, the dialog text is wrapped in a div that is referenced by aria-describedby.
- When the dialog closes, to maintain the user's point of regard, focus returns to the Verify Address button.
- The text of this dialog describes design considerations for initial focus and accessible descriptions in dialogs with large amounts of text.
Address Added dialog (id=dialog3):
- Initial focus is set on the OK button, which is the last focusable element. This is for efficiency since most users will simply dismiss the dialog as soon as they have read the message. Users can press Tab to focus on the My Profile link.
- The element containing the dialog message is referenced by aria-describedby to hint to screen readers that it should be announced when the dialog opens.
- When the dialog closes, the user's point of regard is maintained by setting focus on the Add Delivery Address button.
End of the Road! dialog (id=dialog4):
- This dialog has only one focusable element, which receives focus when the dialog opens.
- Like dialog3, aria-describedby is used to facilitate message announcement for screen reader users.
- Like all other dialogs in this example except for the Address Added confirmation dialog, when it closes, the user's point of regard is maintained by returning focus to the element that triggered display of the dialog.
| Key | Function |
|---|---|
| Tab |
| | Shift + Tab |
| | Escape | Closes the dialog. |
| Role | Attribute | Element | Usage |
|---|---|---|---|
dialog | div | Identifies the element that serves as the dialog container. | |
aria-labelledby=IDREF | div | Gives the dialog an accessible name by referring to the element that provides the dialog title. | |
aria-describedby=IDREF | div |
|
| | aria-modal=true | div | Tells assistive technologies that the windows underneath the current dialog are not available for interaction (inert). |
aria-modal and aria-hiddenaria-modal property was introduced in ARIA 1.1. As a new property, screen reader users may experience varying degrees of support for it.aria-modal property to the dialog element replaces the technique of using aria-hidden on the background for informing assistive technologies that content outside a dialog is inert.aria-hidden is used to make content outside a dialog inert for assistive technology users, it is important that:aria-hidden is set to true on each element containing a portion of the inert layer.aria-hidden set to true.Learn how to interpret and use assistive technology support data
To copy the following HTML code, please open it in CodePen.