Skip to content

Commit

Permalink
Don't change focus when re-focusing delegatesFocus shadowhost
Browse files Browse the repository at this point in the history
I was implementing the new dialog shadowdom initial focus goodness when
I noticed this in chromium:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/element.cc;l=4714-4718;drc=82b10d45463bbc3d019f5ef981dc8afeb8900a6d

When getting the focusable area of a target, in the case that the
target is a shadow-incuding inclusive ancestor of the currently focused
element, the spec says to return null, but chromium's implementation
returns the currently focused element instead and cites this issue:
WICG/webcomponents#840

I'm not certain exactly what the consensus was, but I do see that this
spec PR and test was made in response:
whatwg#5039
web-platform-tests/wpt#19867
The added test doesn't fail if I return null like the spec says to do,
but dialog-focus-shadow-double-nested.html does fail if I return null
with this error message:
```
FAIL showModal() assert_equals: document.activeElement expected Element node <div></div> but got Element node <button tabindex="-1">Focusable</button>
```

Based on this test failure and reading the WICG issue, I believe that we
should be returning the currently focused element, which this patch
does.
  • Loading branch information
josepharhar committed Oct 29, 2022
1 parent 7d8951c commit 1f4e724
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source
Expand Up @@ -76838,9 +76838,11 @@ partial interface <span id="NavigatorUserActivation-partial">Navigator</span> {

<dd>
<ol>
<li><p>If <var>focus target</var> is a <span>shadow-including inclusive ancestor</span> of the
<span>currently focused area of a top-level browsing context</span>'s <span>DOM anchor</span>,
then return null.</p></li>
<li><p>Let <var>focusedElement</var> be the <span>currently focused area of a top-level
browsing context</span>'s <span>DOM anchor</span>.</p></li>

<li><p>If <var>focus target</var> is a <span>shadow-including inclusive ancestor</span> of
<var>focusedElement</var>, then return <var>focusedElement</var>.</p></li>

<li><p>Return the <span>focus delegate</span> for <var>focus target</var> given <var>focus
trigger</var>.</p></li>
Expand Down

0 comments on commit 1f4e724

Please sign in to comment.