-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #688 from sh0ji/alertdialog-example
Add Alert Dialog Example and update existing modal dialog.
- Loading branch information
Showing
6 changed files
with
663 additions
and
236 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Alert and Message Dialogs Example | WAI-ARIA Authoring Practices 1.1</title> | ||
<!-- Core js and css shared by all examples; do not modify when using this template. --> | ||
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/2016/base.css"> | ||
<link rel="stylesheet" href="../css/core.css"> | ||
<script src="../js/examples.js"></script> | ||
<script src="../js/highlight.pack.js"></script> | ||
<script src="../js/app.js"></script> | ||
<!-- js from the dialog-modal example --> | ||
<script src="../js/utils.js"></script> | ||
<script src="js/dialog.js"></script> | ||
<!-- js and css for this example. --> | ||
<link href="css/dialog.css" rel="stylesheet"> | ||
<script src="js/alertdialog.js"></script> | ||
</head> | ||
|
||
<body> | ||
<nav aria-labelledby="ex_related" class="feedback"> | ||
<header id="ex_related">Related Links</header> | ||
<ul> | ||
<li><a href="../../#browser_and_AT_support">Browser and Assistive Technology Support</a></li> | ||
<li><a href="https://github.com/w3c/aria-practices/issues/new">Report Issue</a></li> | ||
<li><a href="https://github.com/w3c/aria-practices/projects/20">Related Issues</a></li> | ||
<li><a href="../../#alertdialog">Design Pattern</a></li> | ||
</ul> | ||
</nav> | ||
<main aria-labelledby="main_label"> | ||
<h1 id="main_label">Alert Dialog Example</h1> | ||
<p> | ||
The below example demonstrates the <a href="../../#alertdialog">design pattern for an alert dialog</a>. | ||
The <a href="../../#alert">design pattern for an alert</a> is also demonstrated to allow the user to experience the difference between the two patterns. | ||
</p> | ||
<p>User interactions for this interactive include:</p> | ||
<ul> | ||
<li>The "notes" <code>textarea</code> contains editable text that you are encouraged to modify.</li> | ||
<li> | ||
The "discard" <code>button</code> triggers a confirmation dialog. | ||
<ul> | ||
<li>Clicking "yes" will remove all contents of both the notes field and the user's local storage</li> | ||
<li>Clicking "no" or pressing <kbd>escape</kbd> will simply close the dialog.</li> | ||
<li>The "discard" <code>button</code> is disabled if the notes field does not contain any text.</li> | ||
</ul> | ||
</li> | ||
<li> | ||
The "save" <code>button</code> saves the contents of the "notes" <code>textarea</code> to your <a href="https://www.w3.org/TR/webstorage/#the-localstorage-attribute">local storage</a>. | ||
<ul> | ||
<li>A successful save will trigger a short <code>[role="alert"]</code> to notify you that your notes have been saved.</li> | ||
<li>The "save" <code>button</code> is disabled if the user's local storage value is the same as the <code>textarea</code> value.</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<p>Similar examples include:</p> | ||
<ul> | ||
<li><a href="alert.html">Alert</a>: a basic alert.</li> | ||
<li><a href="../dialog-modal/dialog.html">Modal Dialog</a>: an example of multiple modal dialogs.</li> | ||
</ul> | ||
<section aria-labelledby="ex_label"> | ||
<h2 id="ex_label">Example</h2> | ||
<div role="separator" id="ex_start_sep" aria-labelledby="ex_start_sep ex_label" aria-label="Start of"></div> | ||
<div id="ex_alertdialog"> | ||
<label for="notes">Notes</label> | ||
<textarea class="notes" name="notes" id="notes" rows="7">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab, similique, consequatur eaque, mollitia repellat cumque numquam fuga hic illo voluptas, alias officiis possimus assumenda natus eos ex. Quo, enim neque!</textarea> | ||
<button type="button" aria-controls="notes" id="notes_save">Save</button> | ||
<button type="button" aria-controls="notes" id="notes_discard" onclick="openAlertDialog('alert_dialog', this)">Discard</button> | ||
<div role="alert" id="alert_toast" class="toast hidden">Nothing to discard.</div> | ||
<div class="dialog-backdrop no-scroll"> | ||
<div id="alert_dialog" role="alertdialog" aria-modal="true" aria-labelledby="dialog_label" aria-describedby="dialog_desc" class="hidden"> | ||
<h2 id="dialog_label" class="dialog_label">Confirmation</h2> | ||
<div id="dialog_desc" class="dialog_desc"> | ||
<p>Are you sure you want to discard all of your notes?</p> | ||
</div> | ||
<div class="dialog_form_actions"> | ||
<button type="button" onclick="closeDialog(this)">No</button> | ||
<button type="button" aria-controls="notes" id="notes_confirm" onclick="discardInput(this)">Yes</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div role="separator" id="ex_end_sep" aria-labelledby="ex_end_sep ex_label" aria-label="End of"></div> | ||
</section> | ||
<section aria-labelledby="a11y_label"> | ||
<h2 id="a11y_label">Accessibility Features</h2> | ||
<p> | ||
Note that this example uses code from the <a href="../dialog-modal/dialog.html">modal dialog example</a> to handle the behavior of the <code>alertdialog</code>. | ||
Referencing that example may also be useful. | ||
</p> | ||
<ol> | ||
<li>The accessible label for the alert dialog is set to its heading ("Confirmation").</li> | ||
<li>The dialog's prompt ("Are you sure...?") is referenced via <code>aria-describedby</code> to ensure that the user is immediately aware of the prompt.</li> | ||
<li> | ||
Focus is automatically set to the first focusable element inside the dialog, which is the "No" <code>button</code>. | ||
This is the least destructive action, and will prevent the user from accidentally confirming the dialog. | ||
</li> | ||
<li>The user can dismiss the dialog with <kbd>Escape</kbd> at any time, or by clicking the "No" <code>button</code>.</li> | ||
<li> | ||
Once the user has removed the contents of the notes <code>textarea</code>, clicking the "discard notes" <code>button</code> cannot do anything. | ||
To communicate this to the user, an alert with <code>role="alert"</code> is triggered. | ||
</li> | ||
</ol> | ||
</section> | ||
<section aria-labelledby="kbd_label"> | ||
<h2 id="kbd_label">Keyboard Support</h2> | ||
<table aria-labelledby="kbd_label" class="def"> | ||
<thead> | ||
<tr> | ||
<th>Key</th> | ||
<th>Function</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th><kbd>Tab</kbd></th> | ||
<td> | ||
<ul> | ||
<li>Moves focus to next focusable element inside the dialog.</li> | ||
<li>When focus is on the last focusable element in the dialog, moves focus to the first focusable element in the dialog.</li> | ||
</ul> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th><kbd>Shift + Tab</kbd></th> | ||
<td> | ||
<ul> | ||
<li>Moves focus to previous focusable element inside the dialog.</li> | ||
<li>When focus is on the first focusable element in the dialog, moves focus to the last focusable element in the dialog.</li> | ||
</ul> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th><kbd>Escape</kbd></th> | ||
<td>Closes the dialog.</td> | ||
</tr> | ||
<tr> | ||
<th><kbd>Command + S</kbd></th> | ||
<td>(Mac only) Save the contents of the notes <code>textarea</code> when focused.</td> | ||
</tr> | ||
<tr> | ||
<th><kbd>Control + S</kbd></th> | ||
<td>(Windows only) Save the contents of the notes <code>textarea</code> when focused.</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
<section aria-labelledby="rps_label"> | ||
<h2 id="rps_label">Role, Property, State, and Tabindex Attributes</h2> | ||
<table aria-labelledby="rps_label" class="data attributes"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Role</th> | ||
<th scope="col">Attribute</th> | ||
<th scope="col">Element</th> | ||
<th scope="col">Usage</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th scope="row"><code>alertdialog</code></th> | ||
<td></td> | ||
<td><code>div</code></td> | ||
<td> | ||
Identifies the element that serves as the alert dialog container. | ||
</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<th scope="row"><code>aria-labelledby=<q>IDREF</q></code></th> | ||
<td><code>div</code></td> | ||
<td> | ||
Gives the alert dialog an accessible name by referring to the element that provides the alert dialog title. | ||
</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<th scope="row"><code>aria-describedby=<q>IDREF</q></code></th> | ||
<td><code>div</code></td> | ||
<td> | ||
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. | ||
</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<th scope="row"><code>aria-modal=<q>true</q></code></th> | ||
<td><code>div</code></td> | ||
<td> | ||
Tells assistive technologies that the windows underneath the current alert dialog are not available for interaction (inert). | ||
</td> | ||
</tr> | ||
<tr> | ||
<th scope="row"><code>alert</code></th> | ||
<td></td> | ||
<td><code>div</code></td> | ||
<td> | ||
Identifies the element that serves as the alert notification. | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<h3>Notes on <code>aria-modal</code> and <code>aria-hidden</code></h3> | ||
<ol> | ||
<li> | ||
The <code>aria-modal</code> property was introduced in ARIA 1.1. | ||
As a new property, screen reader users may experience varying degrees of support for it. | ||
</li> | ||
<li> | ||
Applying the <code>aria-modal</code> property to the <code>dialog</code> element | ||
replaces the technique of using <code>aria-hidden</code> on the background for informing assistive technologies that content outside a dialog is inert. | ||
</li> | ||
<li> | ||
In legacy dialog implementations where <code>aria-hidden</code> is used to make content outside a dialog inert for assistive technology users, it is important that: | ||
<ol> | ||
<li><code>aria-hidden</code> is set to <code>true</code> on each element containing a portion of the inert layer.</li> | ||
<li>The dialog element is not a descendant of any element that has <code>aria-hidden</code> set to <code>true</code>.</li> | ||
</ol> | ||
</li> | ||
</ol> | ||
</section> | ||
<section aria-labelledby="src_label"> | ||
<h2 id="src_label">Javascript and CSS Source Code</h2> | ||
<ul> | ||
<li> CSS: <a href="css/dialog.css" type="text/css">dialog.css</a></li> | ||
<li> Javascript: <a href="js/alertdialog.js" type="text/javascript">alertdialog.js</a>, <a href="js/dialog.js" type="text/javascript">dialog.js</a></li> | ||
</ul> | ||
</section> | ||
<section aria-labelledby="sc1_label"> | ||
<h2 id="sc1_label">HTML Source Code</h2> | ||
<div role="separator" id="sc1_start_sep" aria-labelledby="sc1_start_sep sc1_label" aria-label="Start of"></div> <pre><code id="sc1"></code></pre> | ||
<div role="separator" id="sc1_end_sep" aria-labelledby="sc1_end_sep sc1_label" aria-label="End of"></div> | ||
<script> | ||
sourceCode.add('sc1', 'ex_alertdialog'); | ||
sourceCode.make(); | ||
</script> | ||
</section> | ||
</main> | ||
<nav> | ||
<a href="../../#alertdialog">Alert and Message Dialogs Design Pattern in WAI-ARIA Authoring Practices 1.1</a> | ||
</nav> | ||
</body> | ||
</html> |
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
Oops, something went wrong.