Skip to content

Add the focusreset event - #13050

Open
noamr wants to merge 7 commits into
mainfrom
noamr/focus-reset
Open

noamr wants to merge 7 commits into
mainfrom
noamr/focus-reset

Conversation

@noamr

@noamr noamr commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fire a focusreset event at the Document, if focus was reset to the viewport due to a focused element being removed, and wasn't since restored.

The timing of the event is in the mutation observer microtask, together with slotchange events.

Together with whatwg/dom#1512

We keep a "has pending focus reset" flag on the document (see the DOM PR) when a focused element is removed, and check it shortly after (in the mutation observer microtask).

The asynchronous check is there to avoid being able to observe intermediate DOM state while removing a node tree.
The firing happens in a microtask rather in the rendering steps to make sure DOM changes in the focusreset handler are picked up in the next or current render - e.g. focusreset might be called in the middle of a ResizeObserver callback.

Fixes #12842.

(See WHATWG Working Mode: Changes for more details.)


/document-lifecycle.html ( diff )
/dom.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/interaction.html ( diff )
/webappapis.html ( diff )

@noamr
noamr marked this pull request as draft October 8, 2026 14:55
@noamr
noamr marked this pull request as ready for review October 8, 2026 19:28
@noamr
noamr marked this pull request as draft October 11, 2026 20:40
@noamr
noamr force-pushed the noamr/focus-reset branch from 9de3d82 to 7ac0b1a Compare October 12, 2026 10:10
noamr added 5 commits October 13, 2026 11:02
Fire a focusreset event at the Document when the focus fixup in the update the rendering steps resets focus to the viewport, either because the focused area stopped being focusable, or because the focused element was removed (which synchronously resets focus).

Fixes #12842.
@noamr
noamr force-pushed the noamr/focus-reset branch from 7ac0b1a to 82ae5e6 Compare October 13, 2026 10:32
@noamr
noamr marked this pull request as ready for review October 13, 2026 10:48
@noamr
noamr force-pushed the noamr/focus-reset branch from 82ae5e6 to 178f554 Compare October 13, 2026 11:23
@noamr

noamr commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@emilio or @zcorpan, would you like to take an initial look?
This is ready including tests etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Alternative to blur and focusout on removal

1 participant