Repository navigation
Move focus to a defined place when a window is closed from the keyboard - #1375
Open
captbaritone wants to merge 4 commits into
Open
captbaritone wants to merge 4 commits into
captbaritone wants to merge 4 commits into
Conversation
|
Size Change: +605 B (+0.12%) Total Size: 491 kB 📦 View Changed
|
captbaritone
force-pushed
the
a11y-focus-on-close
branch
3 times, most recently
from
October 15, 2026 16:59
f3376e1 to
f731955
Compare
FocusTarget wraps the contents of every window, so give it role="group" and an accessible name: "Main window", "Equalizer", "Playlist" or "Milkdrop". This tells screen reader users which window a control belongs to, and lets tests scope role-based queries to a window (several windows have a "Close" button).
Closing a window removes the focused element, and the browser drops focus to <body>. For keyboard users, move focus instead to the window that contained it (if still open), else the main window, else any open window, else the Webamp root node (now tabIndex=-1, with its focus outline suppressed like everything else in Webamp). Pointer users are unaffected: moving focus selects the window it lands in, which would visibly change its title bar. Focus is also left alone if the user had already moved it elsewhere in the page, so embedders can move focus in their onClose handler.
captbaritone
force-pushed
the
a11y-focus-on-close
branch
from
October 15, 2026 17:19
f731955 to
66891bd
Compare
✅ Deploy Preview for tourmaline-kringle-c98715 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a keyboard user closes a window, the focused Close button is removed from the DOM and the browser drops focus to
<body>. The user loses their place, and pressing Tab starts over from the top of the page.Change
A new
useRestoreFocusOnRemoval(webampNode)hook, used byApp, watches for this and moves focus to the first of:#webamproot node, when every window is closed (including when Webamp itself is closed from the main window's Close button)Windows are found by a new
data-window-idattribute onFocusTarget. The root node getstabIndex = -1, and#webamp:focusjoins the existingoutline: 0rule.When it applies:
document.activeElementmust now be<body>.onClosehandler can therefore move focus to its own control, e.g. a "Reopen" button, and that wins.FocusTarget, it uses aMutationObserver, because Firefox doesn't fireblur/focusoutwhen a focused element is removed.onClosestill fires as before.Testing
useRestoreFocusOnRemoval.test.tsxcovers:tsc,eslint,prettier --checkandvitest runpass locally.