Skip to content

Add tabindex and arrow/Enter/Space keyboard navigation for cards #208

@arasaka-net

Description

@arasaka-net

Make card elements focusable via tabindex="0" and add arrow-key focus cycling, Enter/Space activation, so the game board is operable without a mouse. Currently cards are non-focusable divs and all keyboard shortcuts require prior mouse selection.

Context
Cards are created as plain <div> elements with no tabindex attribute, making them invisible to keyboard navigation. The existing keyboard handler in keyboard.js only operates on a selectedCard variable that is set exclusively by the mouse grab event in card.js. A keyboard-only user cannot select, flip, rotate, or interact with any card. Adding tabindex="0" to cards, arrow-key focus cycling between .game-card elements, and Enter/Space as activation keys (flip) closes this accessibility gap with a bounded change to two files.

Affected Files

  • src/scripts/card.js:7 — Add tabindex="0" to the cardElement created in createCard
  • src/scripts/card.js:29 — Add a focus event listener that calls selectCard so keyboard focus and selection stay in sync
  • src/scripts/keyboard.js:27 — Add ArrowLeft/ArrowRight cases to cycle focus between .game-card elements, and Enter/Space to toggle flip
  • src/scripts/keyboard.test.js — Add tests for arrow-key focus cycling and Enter/Space flip activation

Requirements

  • Every card element created by createCard has tabindex="0" so it appears in the tab order
  • Pressing ArrowRight moves focus to the next .game-card sibling in DOM order; ArrowLeft moves to the previous
  • Arrow-key navigation wraps around — pressing right on the last card focuses the first, and vice versa
  • Pressing Enter or Space on a focused card toggles its flipped class, matching the F key behavior
  • Focusing a card via Tab or arrow keys calls selectCard so R/F/Delete shortcuts operate on the focused card
  • The text-input guard (INPUT/TEXTAREA focus check) applies to all new key bindings
  • Tests verify: arrow-key cycling, wrap-around, Enter/Space flip, focus-sets-selection, input guard

Verification

  • grep -n 'tabindex' src/scripts/card.js
  • grep -n 'Arrow' src/scripts/keyboard.js
  • npm test -- --reporter=verbose 2>&1 | grep -iE 'arrow|enter|space|tabindex|focus'
  • npm test

Not In Scope

  • Do not add ARIA live regions or screen-reader announcements
  • Do not change the visual styling of focused cards beyond what the browser provides natively
  • Do not add keyboard navigation for tokens or decks in this issue

Evidence

  • src/scripts/card.js:7cardElement is created via document.createElement("div") with no tabindex — it is not keyboard-focusable
  • src/scripts/keyboard.js:27-44 — Switch statement handles only r, R, f, F, Delete, Escape — no ArrowLeft, ArrowRight, Enter, or Space cases
  • src/scripts/card.js:33-36 — The grab event listener calls selectCard, but grab is only dispatched by mouse mousedown — no keyboard path sets selection

Arasaka Queue Planning Division.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions