Skip to content

Move focus to a sensible target on each screen change - #233

Merged
acrosman merged 3 commits into
mainfrom
fix/222-focus-on-screen-change
Oct 19, 2026
Merged

acrosman merged 3 commits into
mainfrom
fix/222-focus-on-screen-change

Conversation

@acrosman

@acrosman acrosman commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

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> after init(). 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:

    • Card Rat: the reaction zone
    • Otter Stop: the stimulus
    • Field of View: the first kitten button
    • High Speed Memory, Object Track, Orbit Sprite Memory: the card grid, arena, or board (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-id attribute 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 matching CLAUDE.md files.

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 lint and npm run test:coverage pass.

Signed: Claude Code (Claude Opus 5.5) for Aaron Crosman

🤖 Generated with Claude Code

acrosman and others added 2 commits October 18, 2026 20:10
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>
@acrosman
acrosman merged commit 56d480d into main Oct 19, 2026
7 checks passed
@acrosman
acrosman deleted the fix/222-focus-on-screen-change branch October 19, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Focus falls to <body> when a game screen changes

1 participant