You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- ARIA APG covers non-HTML modal dialogs, so we don’t need to repeat all of that content here.
- SCR37 was very out of date
- HTML `dialog` element has cross-browser support now
- SCR37 and working example deleted.
- note: I couldn’t find any HTML working examples, do didn’t create one for this.
<h1>Creating Dialogs With The <abbrtitle="HyperText Markup Language">HTML</abbr><codeclass="language-html">dialog</code> Element</h1>
9
+
<sectionclass="meta">
10
+
<pclass="id">ID: </p>
11
+
<pclass="technology">Technology: html</p>
12
+
<pclass="type">Type: Technique</p>
13
+
</section>
14
+
<sectionid="applicability">
15
+
<h2>When to Use</h2>
16
+
<p>HTML</p>
17
+
</section>
18
+
<sectionid="description">
19
+
<h2>Description</h2>
20
+
<p>Site designers often want to create modal dialogs to get users to focus on a task-related activity outside of the rest of the page's content. Although this can be accomplished using <ahref="https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/">ARIA to create a modal dialog</a>, the HTML <codeclass="language-html">dialog</code> element can also be used. As well as meeting <ahref="https://www.w3.org/TR/using-aria/#rule1">the first rule of ARIA</a>, the HTML <codeclass="language-html">dialog</code> element offers several advantages to its ARIA equivalent, with the browser handling these features:</p>
21
+
<ul>
22
+
<li>focus management into the newly-opened modal <codeclass="language-html">dialog</code>;</li>
23
+
<li>focus management back onto the triggering element (assuming the trigger is still on the page) when the modal <codeclass="language-html">dialog</code> is closed;</li>
24
+
<li>trapping keyboard focus inside the modal <codeclass="language-html">dialog</code>;</li>
25
+
<li>with no extra code, the underlying page is hidden from assistive technology when the modal <codeclass="language-html">dialog</code> is open;</li>
26
+
<li>the use of the <kbd>Escape</kbd> key to close the modal <codeclass="language-html">dialog</code>.</li>
27
+
</ul>
28
+
<p>This technique uses the HTML <codeclass="language-html">dialog</code> element rather than the ARIA equivalent.</p>
29
+
</section><sectionid="examples"><h2>Examples</h2>
30
+
<sectionclass="example">
31
+
<h3>A dialog to sign up to a mailing list</h3>
32
+
<p>This is an example of using a modal <codeclass="language-html">dialog</code> element to show a mailing-list sign-up form to a user. The main part of the page contains a <codeclass="language-html">button</code> element that, when activated, triggers the appearance of the modal <codeclass="language-html">dialog</code>. The <codeclass="language-html">button</code> uses the <codeclass="language-html">aria-controls</code> property to create a programmatic connection between the <codeclass="language-html">button</code> and the <codeclass="language-html">dialog</code>; the <codeclass="language-html">aria-haspopup</code> property, set to <codeclass="language-html">dialog</code>, to tell assistive technology that the <codeclass="language-html">button</code> controls a <codeclass="language-html">dialog</code>, and the <codeclass="language-html">type</code> attribute to tell the browser that this isn't a <codeclass="language-html">submit</code><codeclass="language-html">button</code>.</p>
33
+
34
+
<p>When the modal <codeclass="language-html">dialog</code> is opened, the browser will hide all of the content on the underlying page from assistive technology. For example: a screen reader will not announce any of the content. Additionally, focusing with the keyboard is constrained to the the <codeclass="language-html">dialog</code> element's focusable content and the browser's controls. The browser takes care of focus management for us by putting the focus onto the first focusable element in the dialog's <abbrtitle="Document Object Model">DOM</abbr>, which in this demo is the <codeclass="language-html">h1</code> element because it has a <codeclass="language-html">tabindex="-1"</code> attribute, making it focusable by scripts. Note that, although the <codeclass="language-html">dialog</code>'s close <codeclass="language-html">button</code> is visibly before the <codeclass="language-html">h1</code>, it is the last item in the <codeclass="language-html">dialog</code>'s DOM. If the <codeclass="language-html">button</code> was first, it would receive focus when dialog was opened, which could result in the <codeclass="language-html">dialog</code> being closed by mistake if the <codeclass="language-html">button</code> was accidentally activated.</p>
<p>The script toggles the display of the <codeclass="language-html">dialog</code>. The HTML <codeclass="language-html">dialog</code> element can be opened using two different commands: <codeclass="language-javascript">show()</code> (for non-modal <codeclass="language-html">dialog</code>s), and <codeclass="language-javascript">showModal()</code> (for modal <codeclass="language-html">dialog</code>s).</p>
<li>Find the components on the page that trigger modal <codeclass="language-html">dialog</code> elements.</li>
174
+
<li>Check that each <codeclass="language-html">dialog</code> can be opened using the keyboard to activate the triggering element (for example: activate a <codeclass="language-html">button</code> by pressing the <kbd>Enter</kbd> key or <kbd>Space Bar</kbd>.</li>
175
+
<li>When the <codeclass="language-html">dialog</code> is opened, check that focus is placed inside it.</li>
176
+
<li>While the <codeclass="language-html">dialog</code> is open, check that focus is trapped inside the <codeclass="language-html">dialog</code>.</li>
177
+
<li>When the <codeclass="language-html">dialog</code> is closed, check that focus is placed back onto the triggering element, if that is still on the page.</li>
178
+
</ol>
179
+
</section>
180
+
<sectionclass="results"><h3>Expected Results</h3>
181
+
<ul>
182
+
<li>Checks #2, #3, #4 and #5 are true. </li>
183
+
</ul>
184
+
</section>
185
+
</section>
186
+
<sectionid="related">
187
+
<h2>Related Techniques</h2>
188
+
<ul>
189
+
<li>
190
+
<ahref="../client-side-script/SCR26">SCR26</a>
191
+
</li>
192
+
<li>
193
+
<ahref="../general/G59">G59</a>
194
+
</li>
195
+
</ul>
196
+
</section>
197
+
<sectionid="resources">
198
+
<h2>Resources</h2>
199
+
<ul>
200
+
<li>
201
+
<ahref="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">HTML - the <codeclass="language-html">dialog</code> element</a>.
202
+
</li>
203
+
<li>
204
+
<ahref="https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element">HTML - the <codeclass="language-html">button</code> element</a>.
0 commit comments