Alert Dialog Example
++ The below example demonstrates the design pattern for an alert dialog. + The design pattern for an alert is also demonstrated to allow the user to experience the difference between the two patterns. +
+User interactions for this interactive include:
+-
+
- The "notes"
textarea
contains editable text that you are encouraged to modify.
+ -
+ The "discard"
button
triggers a confirmation dialog. +-
+
- Clicking "yes" will remove all contents of both the notes field and the user's local storage +
- Clicking "no" or pressing escape will simply close the dialog. +
- The "discard"
button
is disabled if the notes field does not contain any text.
+
+ -
+ The "save"
button
saves the contents of the "notes"textarea
to your local storage. +-
+
- A successful save will trigger a short
[role="alert"]
to notify you that your notes have been saved.
+ - The "save"
button
is disabled if the user's local storage value is the same as thetextarea
value.
+
+ - A successful save will trigger a short
Similar examples include:
+-
+
- Alert: a basic alert. +
- Modal Dialog: an example of multiple modal dialogs. +
Example
+ +Confirmation
+Are you sure you want to discard all of your notes?
+Accessibility Features
+
+ Note that this example uses code from the modal dialog example to handle the behavior of the alertdialog
.
+ Referencing that example may also be useful.
+
-
+
- The accessible label for the alert dialog is set to its heading ("Confirmation"). +
- The dialog's prompt ("Are you sure...?") is referenced via
aria-describedby
to ensure that the user is immediately aware of the prompt.
+ -
+ Focus is automatically set to the first focusable element inside the dialog, which is the "No"
button
. + This is the least destructive action, and will prevent the user from accidentally confirming the dialog. +
+ - The user can dismiss the dialog with Escape at any time, or by clicking the "No"
button
.
+ -
+ Once the user has removed the contents of the notes
textarea
, clicking the "discard notes"button
cannot do anything. + To communicate this to the user, an alert withrole="alert"
is triggered. +
+
Keyboard Support
+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, Property, State, and Tabindex Attributes
+Role | +Attribute | +Element | +Usage | +
---|---|---|---|
alertdialog |
+ + | div |
+ + Identifies the element that serves as the alert dialog container. + | +
+ | aria-labelledby= |
+ div |
+ + Gives the alert dialog an accessible name by referring to the element that provides the alert dialog title. + | +
+ | aria-describedby= |
+ 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= |
+ 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. + | +
Notes on aria-modal
and aria-hidden
+ -
+
-
+ The
aria-modal
property was introduced in ARIA 1.1. + As a new property, screen reader users may experience varying degrees of support for it. +
+ -
+ Applying the
aria-modal
property to thedialog
element + replaces the technique of usingaria-hidden
on the background for informing assistive technologies that content outside a dialog is inert. +
+ -
+ In legacy dialog implementations where
aria-hidden
is used to make content outside a dialog inert for assistive technology users, it is important that: +-
+
aria-hidden
is set totrue
on each element containing a portion of the inert layer.
+ - The dialog element is not a descendant of any element that has
aria-hidden
set totrue
.
+
+
Javascript and CSS Source Code
+-
+
- CSS: dialog.css +
- Javascript: alertdialog.js, dialog.js +
HTML Source Code
+
+
+
+