-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add notes explaining how <dialog>.showModal() focuses #5534
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
It resets focus to the body/viewport instead of doing nothing, right?
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.
No, that step does nothing. The step on line 56630 is the one that resets to the body/viewport.
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.
Ah I see. I expected it to be here because in chrome's implementation it seems like it resets focus to body in the dialog focusing steps, but I trust this is equivalent.
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.
Yeah. I'm unsure how closely the "focus fixup rule" matches to implementation strategy. I guess it's possible that implementations monitor for all the various situations that make something unfocusable, and then use that to reset focus to the body. But probably more likely implementations have ad-hoc reset-focus-to-body calls on cases like the dialog focus steps, element removal, etc.
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.
Makes sense. Thanks!
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.
How about
show
? Does it mean the thing that has been focused previously should remain focused ifcontrol
is not focusable? I think Chrome's dialog focusing steps applies to bothshow
andshowModal
.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 both for the delay in getting back to you on this.
This is correct, per the spec as-is (including after these informative notes get added).
Yep, you're right, ugh. https://boom-bath.glitch.me/dialog-open-focus.html shows this.
However, this seems like pretty buggy behavior in Chrome, because Chrome "clears the focus" without actually focusing the body element. That is, no focus events get fired on it.
As far as I can tell the way to spec what Chrome is doing would be to run the unfocusing steps for the focused area of the document if control is not focusable. This is pretty awkward and unprecedented.
I would rather treat this as a Chrome bug in the case of
show()
. What do you think, @josepharhar?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.
As long as it doesn't break any websites I'm happy to change the behavior in chrome.
Would the difference just be to fire the focus event on
<body>
when the focus gets set to it?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.
Not quite. The idea would be to change step 4 of the algorithm you cited at web-platform-tests/wpt#23485 (comment) to "do nothing" if the caller is show(). (If the caller is showModal(), then it stays as-is.)
This seems unlikely to break anything. My guess is that show() has pretty low usage (compared to showModal()), and it would just amount to a small user experience improvement. The only way it'd cause web-compat problems is if people were expecting document.activeElement to get reset to the body, but it's hard to imagine how code could depend on that.