third_party/aria-practices/src/content/patterns/alertdialog/examples/alertdialog.html
The below example of a confirmation prompt demonstrates the Alert Dialog Pattern. It also includes an example of the Alert Pattern to make comparing the experiences provided by the two patterns easy.
To use this example:
Activate the "discard" button to trigger a confirmation dialog that has the alertdialog role.
Activate the "save" button to trigger an alert when the contents of the "Notes" text area is saved to local storage.
Modify the "notes" text area as needed to enable and disable the discard and save functions.
Similar examples include:
NotesThis is an example text box, which unsurprisingly contains text. The user is given the option to save this text - which triggers a basic alert - or to discard the text - which triggers an alert dialog that prompts the user for confirmation.
Save Discard
Are you sure you want to discard all of your notes?
NoYes
aria-describedby to ensure that the user is immediately aware of the prompt.button. This is the least destructive action, so focusing "No" helps prevent users from accidentally confirming the destructive "Discard" action, which cannot be undone.aria-disabled is used instead of the HTML disabled attribute so the buttons will remain in the page Tab sequence. This makes it easier for screen reader users to discover the buttons and discern how the interface works.| Key | Function |
|---|---|
| Tab |
| | Shift + Tab |
|
| Escape | Closes the dialog. |
| Command + S | (Mac only) Save the contents of the notes textarea when focused. |
| Control + S | (Windows only) Save the contents of the notes textarea when focused. |
| Role | Attribute | Element | Usage |
|---|---|---|---|
alertdialog | div | Identifies the element that serves as the alert dialog container. | |
aria-labelledby="ID_REFERENCE" | div | Gives the alert dialog an accessible name by referring to the element that provides the alert dialog title. | |
aria-describedby="ID_REFERENCE" | div | Gives the alert dialog an accessible description by referring to the alert dialog content that describes the primary message or purpose of the alert dialog. | |
aria-modal="true" | div | Tells assistive technologies that the windows underneath the current alert dialog are not available for interaction (inert). | |
alert | div | Identifies the element that serves as the alert notification. | |
aria-disabled="true" | button | Tells assistive technology users the button cannot be activated. |
aria-modal and aria-hiddenaria-modal property was introduced in ARIA 1.1. As a relatively 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.To copy the following HTML code, please open it in CodePen.