Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Improve autofocus and delegatesFocus interaction #6990
Improve autofocus and delegatesFocus interaction #6990
Changes from all commits
7db993d
10ccc0a
3de77cb
af8c139
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Shadow host with
delegateFocus = true
is not a focusable area right, so we won't try to delegating the focus to the inner shadow DOM for hosts that haveautofocus
+delegatesFocus = true
?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.
Hmm, you are right. And that is consistent with the existing behavior where you can't delegateFocus to a delegatesFocus shadow root. And you cannot delegatesFocus to an area element's shapes, either, I guess. Because we strictly look for focusable areas when assembling possible focus delegates / possible autofocus delegates.
But that feels a bit weird. Maybe we should fix that, both for the existing case and for this new case? WDYT?
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.
Right now, we look for
focusable area
in the flat tree, so we are able to delegate the focus to an inner shadow DOM with delegatesFocus.So something like this https://jsfiddle.net/8t297ekp/ works. Do I misunderstand something?
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.
I am not sure; I think I might be confused too. In your example,
innerHost
is not a focusable area, right? Only the<input>
is. So it doesn't matter whereinnerHost
is delegatesFocus or not, right? When you try to focushost
, It just finds the<input>
as a flat tree child and focuses that instead, I think...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.
That sounds right. How about an example like this https://jsfiddle.net/41e0zhqn/1/?
I think we'd want the
innerInput
to be focus, however with the current PR, it won't because nothing will be added to thepossible autofocus delegates
, so we go throughpossible focus delegates
, thus theouterInput
is focused?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.
Yes, I agree. I can imagine roughly the following paths to solving this:
Make potential autofocus delegates only care about the
autofocus
attribute, and not care about focusable area-ness.Make potential autofocus delegates include delegatesHost shadow hosts via a one-off addition. I.e. set it to what it currently is plus any descendant delegatesFocus shadow hosts.
Make potential autofocus delegates computation smarter, by having it look at all descendants, call "get the focusable area", and if the result is non-null store it in potential autofocus delegates.
Try to use the flat tree somehow instead of the DOM tree? That was my original approach but @rniwa pointed out in Improve autofocus and delegatesFocus interaction #6990 (comment) that it didn't work that well. I wonder if there's something smarter we can do that lets us stay more symmetric with the non-autofocus case, but I can't think of what that would be.
I think (3) is probably best. WDYT?
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.
So I think rniwa's concern was if we have a DOM like this
We'd want
#outerInput
to be focused, so we don't want to use a flat tree?(3) also sounds the best to me, however, I think we still need to make sure the above example works?
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.
OK, I think I pushed a version of (3) and I believe it works for that case as well. PTAL!
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.
Hmm....So we don't consider inner elements if the ancestor doesn't have
autofocus
. For a case like thisouterInput
is going to be focused, is this expected...?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.
I think that is the desired behavior, although it'd be good to have @rniwa confirm. The way I think about it is that at a per-shadow-tree level, by default you focus the first focusable area, but you can put
autofocus
on something specific to override it. Since there's no autofocus in the first level (i.e. in the shadow-including children of#host
), we focus#outerInput
.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.
Sorry for the long delay reviewing this. After reading and re-reading, I think the last comment (and the current state of the spec text) feels right. The
delegatesfocus
attribute applies to each shadow host individually, and does not "cascade" into contained shadow roots. I like the recursive use of "get the focusable area". So LGTM.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.
Got it, I agree, that makes sense to me.