Repository navigation
Move focus to a sensible target on each screen change - #233
Merged
Merged
Conversation
Opening a game removed the card that had focus, and returning to the menu removed the Return to Menu button, so focus fell to <body> and a screen reader announced nothing about the new screen. A new focusHeading() helper in gameUtils.js focuses the first heading in an element, adding tabindex="-1" when needed. The shell calls it on the game container after init(), so focus lands on the game's title. The shell also remembers which game was opened and, once the menu is rebuilt, focuses the Play button of that game's card. Cards now carry data-game-id so the shell can find it. Clear History rebuilds the menu without a game open, so focus stays on View History. Part of #222 Signed: Claude Code (Claude Opus 5.5) for Aaron Crosman Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End Game sits in the game area, which is hidden when the session ends, so focus fell to <body>. Every game, and the template, now calls focusHeading() on its end panel right after showing it, so focus lands on "Session Ended" and the next Tab reaches Play Again. Each game's tests check where focus lands. Fixtures that were trimmed copies of interface.html gained the panel's heading, and tests whose container was detached attach it so it can take focus. Fixes #222 Signed: Claude Code (Claude Opus 5.5) for Aaron Crosman Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Start and Play Again sit in panels that hide when a session starts. Six games did not move focus anywhere, so it fell to <body> and the next Tab went back to the top of the page. Each of them now focuses its main response control when a session starts: the reaction zone in Card Rat, the stimulus in Otter Stop, the first kitten button in Field of View, and the card grid, arena, or board in High Speed Memory, Object Track, and Orbit Sprite Memory. Those three containers get tabindex="-1" so they can take focus. Four of these games rebuild their answer controls every round, which dropped focus again whenever a removed control had it. A new keepFocusInside() helper in gameUtils.js runs the rebuild and, if the focused control is gone, moves focus to a stable target. Part of #222 Signed: Claude Code (Claude Opus 5.5) for Aaron Crosman Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #222.
Each screen change hid or removed the focused control, so focus fell to
<body>. Now:Game opens: the shell focuses the game's title
<h2>afterinit(). The next Tab goes to Start.Session starts (Start or Play Again): focus moves into the game area. This case is from the issue comment. Four games already did this. The other six now focus:
tabindex="-1")Those last four games rebuild their answer controls every round. A new helper,
keepFocusInside(), keeps focus from dropping when the focused control is removed.Session ends: every game calls a new helper,
focusHeading(), on its end panel. Focus lands on "Session Ended", and the next Tab goes to Play Again.Return to menu: the shell focuses the Play button of the game just played. Cards now have a
data-game-idattribute so the shell can find the right one. After Clear History, focus stays on View History.Both helpers live in
gameUtils.js. Added tests for the helpers, the shell, the card, and each game; every new focus test fails without the fix. Updated the matchingCLAUDE.mdfiles.Checked in the running app with a keyboard-only walk through all ten games: menu → game → Start → End Game → Return to Menu. In the six changed games, I also played rounds with the keyboard to check the round-by-round case. One Space press on Card Rat's focused reaction zone counts once.
npm run lintandnpm run test:coveragepass.Signed: Claude Code (Claude Opus 5.5) for Aaron Crosman
🤖 Generated with Claude Code