Skip to content
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 1 commit into from
Jun 4, 2020

Conversation

domenic
Copy link
Member

@domenic domenic commented May 11, 2020

It was unclear how the "focus fixup rule" came into play, since that
rule is done using action at a distance. This inserts notes explicitly
calling out what happens.

See web-platform-tests/wpt#23485 for background.

/cc @sefeng211 and @josepharhar.


/interactive-elements.html ( diff )

It was unclear how the "focus fixup rule" came into play, since that
rule is done using action at a distance. This inserts notes explicitly
calling out what happens.

See web-platform-tests/wpt#23485 for background.
@domenic domenic added clarification Standard could be clearer topic: focus labels May 11, 2020
<li>
<p>Run the <span>focusing steps</span> for <var>control</var>.</p>

<p class="note">If <var>control</var> is not <span>focusable</span>, this will do nothing. For
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

@domenic domenic May 12, 2020

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks!

Copy link
Contributor

@sefeng211 sefeng211 May 12, 2020

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 if control is not focusable? I think Chrome's dialog focusing steps applies to both show and showModal.

Copy link
Member Author

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.

Does it mean the thing that has been focused previously should remain focused if control is not focusable

This is correct, per the spec as-is (including after these informative notes get added).

I think Chrome's dialog focusing steps applies to both show and showModal.

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

@josepharhar
Copy link
Contributor

Do nothing instead of “clearing focus,” sounds good!

Copy link
Contributor

@sefeng211 sefeng211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sefeng211
Copy link
Contributor

I think we also want tests for this change?

@domenic
Copy link
Member Author

domenic commented May 26, 2020

@sefeng211 yeah, tests would be great! (Although note this isn't a change to the spec, just a clarification. It'll be a change for Chromium though.) Since you're implementing in Firefox, would you be able to write those tests (or modify any existing ones that don't match the spec)?

@dpogue
Copy link

dpogue commented May 26, 2020

This may also be an opportunity to revisit the unresolved discussion about focusing the dialog instead of the first focusable element. #4184 for the proposed spec change, which links to the various previous discussions.

@annevk annevk added the topic: dialog The <dialog> element label May 29, 2020
@domenic domenic requested a review from annevk June 3, 2020 19:19
@annevk annevk merged commit 05f4571 into master Jun 4, 2020
@annevk annevk deleted the dialog-focusing-steps branch June 4, 2020 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: dialog The <dialog> element topic: focus
Development

Successfully merging this pull request may close these issues.

5 participants