-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Further fixes to focus delegation #7361
Conversation
This ensures that focus delegation, used by both delegatesFocus and <dialog>, does not traverse into non-delegatesFocus shadow trees. Otherwise you would get unintuitive results in situations such as the following: <div id="outer"> <#shadowroot delegatesFocus=true> <div id="inner> <#shadowroot delegatesFocus=false> <input> </#shadowroot> </div> </#shadowroot> </div> In such a scenario, with the previous specification, inner.focus() would not focus anything, since inner's shadow root does not delegate focus so we never hit the "focus delegate" algorithm. But outer.focus() would focus the <input> element, since with it having delegatesFocus=true, we use the "focus delegate" algorithm, which would look at all shadow-including descendants. After this change, both inner.focus() and outer.focus() would not focus anything, since the <input> is hidden inside a delegatesFocus=false shadow tree. Discovered in https://matrixlogs.bakkot.com/WHATWG/2021-11-23#L36-L62.
Completely drive-by, unrelated comment: your example could be written thusly, and it would work (at least in Chromium): <div id="outer">
<template shadowroot=open shadowrootdelegatesfocus=true>
<div id="inner">
<template shadowroot=open shadowrootdelegatesfocus=false>
<input>
</template>
</div>
</template>
</div> |
Ping @emilio and/or @sefeng211 and/or @annevk for review :). Happy new year! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The effect of this looks good, though I find it would probably be simpler if this algorithm was written in terms of a shadow-including DOM traversal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilio it's not clear to me the shadow-including terminology from DOM would help here. Potentially you could replace
Set root to root's host's root.
with
Set root to the first shadow-including ancestor of root that is a shadow root or document.
but that does not seem better? Or am I missing something?
And, happy new year to you as well @domenic! |
You want to basically do a regular Dom traversal and dig only into "delegatesfocus" shadow roots, right? Would that not be equivalent? |
I see what you mean. The current approach is trying to maximally reuse definitions, notably "shadow-including descendants" and "shadow-including tree-order". But doing so means we then have to check the ancestors. Instead we could reimplement those definitions (i.e. do our own shadow-including depth-first preorder traversal), and then tweak the result to not traverse into non-delegatesfocus descendants. That might be cleaner indeed. |
I rewrote this to do such a tree traversal. I think the result is actually a lot better, mainly because we can reuse the "get the focusable area" algorithm, which naturally does the recursion we need for tree traversal. It's also more precise than the previous wording of "focusable areas whose DOM anchors are shadow-including descendants", which seems like it could be ambiguous, or mismatch "get the focusable area", in some cases. Unfortunately since it's basically a re-write this does need complete re-review. But I'm optimistic. |
I think I lost the plot a bit, but this new algorithm first goes through descendants and then the shadow host's shadow tree, right? That means that in
y gets focus. |
Yeah. autofocus is supposed to be "hidden" by shadow boundaries; you'd need to put autofocus on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It was a bit harder to review because apparently the PR diff links don't get updated?
D'oh, there are two sets of links (-: |
…n tests, a=testonly Automatic update from web-platform-tests Expand and change dialog focus delegation tests Follows whatwg/html#7361. -- wpt-commits: 4b4b82fbede9d597d92aee1b934e33f4ac1dc971 wpt-pr: 31724
…n tests, a=testonly Automatic update from web-platform-tests Expand and change dialog focus delegation tests Follows whatwg/html#7361. -- wpt-commits: 4b4b82fbede9d597d92aee1b934e33f4ac1dc971 wpt-pr: 31724
…n tests, a=testonly Automatic update from web-platform-tests Expand and change dialog focus delegation tests Follows whatwg/html#7361. -- wpt-commits: 4b4b82fbede9d597d92aee1b934e33f4ac1dc971 wpt-pr: 31724
…n tests, a=testonly Automatic update from web-platform-tests Expand and change dialog focus delegation tests Follows whatwg/html#7361. -- wpt-commits: 4b4b82fbede9d597d92aee1b934e33f4ac1dc971 wpt-pr: 31724
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Bug: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Bug: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067796}
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067796}
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067796}
This reverts commit afeccd1f5b2dd72595abe55bc9ef093f11b495f1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39
This reverts commit afeccd1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4005547 Commit-Queue: Tim Sergeant <tsergeant@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tim Sergeant <tsergeant@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Tim Sergeant <tsergeant@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067950}
This reverts commit afeccd1f5b2dd72595abe55bc9ef093f11b495f1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4005547 Commit-Queue: Tim Sergeant <tsergeant@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tim Sergeant <tsergeant@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Tim Sergeant <tsergeant@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067950}
This reverts commit afeccd1f5b2dd72595abe55bc9ef093f11b495f1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4005547 Commit-Queue: Tim Sergeant <tsergeant@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tim Sergeant <tsergeant@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Tim Sergeant <tsergeant@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067950}
This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: If024ab0f22716c55b439e44b2298e39897ee844e
…or, a=testonly Automatic update from web-platform-tests Implement new dialog shadow focus behavior This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067796} -- wpt-commits: e1d2b674fbcc1ca01eccb624fdd758c38f3407a7 wpt-pr: 36498
…s behavior", a=testonly Automatic update from web-platform-tests Revert "Implement new dialog shadow focus behavior" This reverts commit afeccd1f5b2dd72595abe55bc9ef093f11b495f1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4005547 Commit-Queue: Tim Sergeant <tsergeant@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tim Sergeant <tsergeant@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Tim Sergeant <tsergeant@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067950} -- wpt-commits: 011077556f5634fe685c613564c3325e77387462 wpt-pr: 36838
…or, a=testonly Automatic update from web-platform-tests Implement new dialog shadow focus behavior This implements the new dialog initial focus behavior specified in these changes: whatwg/html#7079 whatwg/html#7284 whatwg/html#7361 whatwg/html#8174 The gist of the changes are: 1. Use the DOM tree instead of the flat tree to search for an element to give initial focus. 2. Don't traverse into shadow roots when looking for elements to give initial focus unless the shadow root has delegatesFocus. This will stay experimental until I have also made the other changes for dialog initial focus: whatwg/html#8199 After those changes have been made as well, I will carefully enable the flag by default. Fixed: 383230, 670130, 1292852 Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067796} -- wpt-commits: e1d2b674fbcc1ca01eccb624fdd758c38f3407a7 wpt-pr: 36498
…s behavior", a=testonly Automatic update from web-platform-tests Revert "Implement new dialog shadow focus behavior" This reverts commit afeccd1f5b2dd72595abe55bc9ef093f11b495f1. Reason for revert: dialog-focus-shadow.html is failing on a couple of mac builders: https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.13%20Tests/57992/overview https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.14%20Tests/28597/overview Original change's description: > Implement new dialog shadow focus behavior > > This implements the new dialog initial focus behavior specified in these > changes: > whatwg/html#7079 > whatwg/html#7284 > whatwg/html#7361 > whatwg/html#8174 > > The gist of the changes are: > 1. Use the DOM tree instead of the flat tree to search for an element to > give initial focus. > 2. Don't traverse into shadow roots when looking for elements to give > initial focus unless the shadow root has delegatesFocus. > > This will stay experimental until I have also made the other changes for > dialog initial focus: whatwg/html#8199 > After those changes have been made as well, I will carefully enable the > flag by default. > > Fixed: 383230, 670130, 1292852 > Change-Id: I13995197f1942aa356cab0f3b41a0e226d1d170d > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3961528 > Reviewed-by: Mason Freed <masonf@chromium.org> > Commit-Queue: Joey Arhar <jarhar@chromium.org> > Cr-Commit-Position: refs/heads/main@{#1067796} Change-Id: I010be9a77fd8c289edb8c028355182d0fe7dec39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4005547 Commit-Queue: Tim Sergeant <tsergeant@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tim Sergeant <tsergeant@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Tim Sergeant <tsergeant@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067950} -- wpt-commits: 011077556f5634fe685c613564c3325e77387462 wpt-pr: 36838
This ensures that focus delegation, used by both delegatesFocus and
<dialog>
, does not traverse into non-delegatesFocus shadow trees. Otherwise you would get unintuitive results in situations such as the following:In such a scenario, with the previous specification, inner.focus() would not focus anything, since inner's shadow root does not delegate focus so we never hit the "focus delegate" algorithm. But outer.focus() would focus the
<input>
element, since with it having delegatesFocus=true, we use the "focus delegate" algorithm, which would look at all shadow-including descendants. After this change, both inner.focus() and outer.focus() would not focus anything, since the<input>
is hidden inside a delegatesFocus=false shadow tree.Discovered in https://matrixlogs.bakkot.com/WHATWG/2021-11-23#L36-L62 by @emilio and @sefeng211. Review from them appreciated.
(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/interaction.html ( diff )
/infrastructure.html ( diff )
/interaction.html ( diff )