Skip to content

Commit

Permalink
Implement dialog initial focus proposal
Browse files Browse the repository at this point in the history
This implements the changes proposed here:
https://github.com/whatwg/html/wiki/dialog--initial-focus,-a-proposal#dialog-draft-text

Specifically:
1. Add a parameter to dialog.show() called preventInitialFocus, which
   prevents the dialog focusing steps from running.
2. Make the dialog focusing steps look at sequentially focusable
   elements instead of any focusable element.

There are additional open issues around dialog initial focus listed here:
whatwg#4184 (comment)

TODO add a conformance requirement about autofocus:
whatwg#7709

TODO consider adding a <p class=XXX> for tab trapping:
whatwg#7707
  • Loading branch information
josepharhar committed Aug 16, 2022
1 parent 814668e commit 2394e21
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -59158,7 +59158,7 @@ interface <dfn interface>HTMLDialogElement</dfn> : <span>HTMLElement</span> {

[<span>CEReactions</span>] attribute boolean <span data-x="dom-dialog-open">open</span>;
attribute DOMString <span data-x="dom-dialog-returnValue">returnValue</span>;
[<span>CEReactions</span>] undefined <span data-x="dom-dialog-show">show</span>();
[<span>CEReactions</span>] undefined <span data-x="dom-dialog-show">show</span>(optional boolean preventInitialFocus);
[<span>CEReactions</span>] undefined <span data-x="dom-dialog-showModal">showModal</span>();
[<span>CEReactions</span>] undefined <span data-x="dom-dialog-close">close</span>(optional DOMString returnValue);
};</code></pre>
Expand Down Expand Up @@ -59243,8 +59243,9 @@ interface <dfn interface>HTMLDialogElement</dfn> : <span>HTMLElement</span> {

<div w-nodev>

<p>When the <dfn method for="HTMLDialogElement"><code data-x="dom-dialog-show">show()</code></dfn>
method is invoked, the user agent must run the following steps:</p>
<p>When the <dfn method for="HTMLDialogElement"><code
data-x="dom-dialog-show">show(preventInitialFocus)</code></dfn> method is invoked, the user agent
must run the following steps:</p>

<ol>
<li><p>If the element already has an <code data-x="attr-dialog-open">open</code> attribute, then
Expand All @@ -59256,7 +59257,8 @@ interface <dfn interface>HTMLDialogElement</dfn> : <span>HTMLElement</span> {
<li><p>Set the <code>dialog</code> element's <span>previously focused element</span> to the
<span>focused</span> element.</p></li>

<li><p>Run the <span>dialog focusing steps</span> for the <code>dialog</code> element.</p></li>
<li><p>If <var>preventInitialFocus</var> flag is not present or is set to false, run the
<span>dialog focusing steps</span> for the <code>dialog</code> element.</p></li>
</ol>

<p>When the <dfn method for="HTMLDialogElement"><code
Expand Down Expand Up @@ -76934,10 +76936,21 @@ END:VCARD</pre>

<ol>
<li>
<p>Let <var>focusable area</var> be <var>child</var>, if <var>child</var> is a
<span>focusable area</span>; otherwise let <var>focusable area</var> be the result of <span
data-x="get the focusable area">getting the focusable area</span> for <var>child</var> given
<var>focus trigger</var>.</p>
<p>Let <var>focusable area</var> be null.</p>

<ol>
<li><p>If <var>focus target</var> is a <code>dialog</code> element and <var>child</var> is
<span>sequentially focusable</span>, let <var>focusable area</var> be
<var>child</var>.</p></li>

<li><p>Otherwise, if <var>focus target</var> is not a <code>dialog</code> element and
<var>child</var> is a <span>focusable area</span>, let <var>focusable area</var> be
<var>child</var>.</p></li>

<li><p>Otherwise, let <var>focusable area</var> be the result of <span data-x="get the
focusable area">getting the focusable area</span> for <var>child</var> given <var>focus
trigger</var>.</p></li>
</ol>

<p class="note">This step can end up recursing, i.e., the <span>get the focusable area</span>
steps might return the <span>focus delegate</span> of <var>child</var>.</p>
Expand Down

0 comments on commit 2394e21

Please sign in to comment.