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

When must the focusing steps be run? #6729

Closed
lpd-au opened this issue Jun 1, 2021 · 1 comment · Fixed by #8392
Closed

When must the focusing steps be run? #6729

lpd-au opened this issue Jun 1, 2021 · 1 comment · Fixed by #8392

Comments

@lpd-au
Copy link

lpd-au commented Jun 1, 2021

Section 6.5.4 Processing model of the HTML specification defines focusing steps that user agents must immediately run "whenever the user attempts to move the focus" (emphasis mine). The same section also defines a focus fixup rule that specifies the behaviour when the focused area of the document stops being a focusable area. (For example, when an <input type=text> element becomes styled with display: none, it is no longer being rendered and hence no longer meets the requirements to be a focusable area.) I quote the normative part of the rule below:

Focus fixup rule: When the designated focused area of the document is removed from that Document in some way (e.g. it stops being a focusable area, it is removed from the DOM, it becomes expressly inert, etc.), designate the Document's viewport to be the new focused area of the document.

I believe this section and the non-normative notes beneath it have multiple areas of ambiguity:

Firstly, I perceive "removed from that Document in some way" to be a very imprecise use of language, likely to be confused with the concept of connectedness and the spec definition of node is removed from a document. I propose this phrasing should be replaced with a clear term or set of terms that better encompass the examples given in both the rule itself and the first accompanying note.

Secondly, it is ambiguous whether the focus fixup rule requires the focusing steps to be run. In my reading it certainly doesn't explicitly call for it, but if the second accompanying note is taken at face value, this would imply that the value of document.activeElement could change without either a focus or blur event being triggered. I propose that either the focusing steps be amended to mention non-user driven focus changes or the focus fixup rule be amended to state the focusing steps must/must not be called, or both.

In my testing, when a focused input element stopped being rendered, browsers appeared to take inconsistent approaches:

  • Chrome ran the focusing steps, designating a new focused area of the document as per step 4.1 of the focus update steps (called for in turn by step 8 of the focusing steps).
  • Firefox and Safari neither ran the focusing steps nor designated a new focused area of the document.

In response to that finding, I also opened a corresponding Chrome bug yesterday: https://bugs.chromium.org/p/chromium/issues/detail?id=1214850

@annevk
Copy link
Member

annevk commented Jun 2, 2021

cc @rakina @rniwa @smaug----

domenic added a commit that referenced this issue Oct 16, 2022
* Split it into two variants: one which runs synchronously on HTML element removal, and one which runs during "update the rendering". Closes #8225.

* Be clear that the fixup does not cause any of the normal focus algorithms to run, and thus blur and change events do not fire. Also, delete the confusing "somehow unfocused without another element being explicitly focused" sentence. Fixes #3847. Fixes #6729.
domenic added a commit that referenced this issue Nov 4, 2022
* Split it into two variants: one which runs synchronously on HTML element removal, and one which runs during "update the rendering". Closes #8225.

* After this split, only the "update the rendering" variant causes the normal focus algorithms to run, and thus blur and change events to fire.

* Delete the confusing "somehow unfocused without another element being explicitly focused" sentence.

Fixes #3847. Fixes #6729.
domenic added a commit that referenced this issue Jan 18, 2023
* Split it into two variants: one which runs synchronously on HTML element removal, and one which runs during "update the rendering". Closes #8225.

* After this split, only the "update the rendering" variant causes the normal focus algorithms to run, and thus blur and change events to fire.

* Delete the confusing "somehow unfocused without another element being explicitly focused" sentence.

Fixes #3847. Fixes #6729.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants