Skip to content

Falling Words: Tab+Enter steals focus to GitHub link, breaks 'Enter to restart' on return #47

Description

@moKshagna-p

Describe the bug

In the Falling Words game, pressing Tab moves focus away from the hidden <input> that captures keyboard events. If Enter is then pressed, whatever element now has focus is activated — typically the GitHub link in the footer. This opens GitHub in a new tab.

When the user returns to the game tab, the game may have ended (via visibilitychange -> endGame()), showing the "enter to restart" overlay. However, pressing Enter does nothing because the hidden input no longer has focus — the handleKeyDown listener is never reached.

To Reproduce

  1. Go to the Falling Words game
  2. Press Tab (focus moves away from the hidden input)
  3. Press Enter (GitHub opens in a new tab)
  4. Close the GitHub tab and return to the game
  5. See the "enter to restart" overlay
  6. Press Enter -- nothing happens

Expected behavior

  • Pressing Enter on the game-over overlay should restart the game regardless of what element has focus (or the hidden input should be automatically refocused).
  • Tab should not be able to steal focus from the game input.

Root cause

The hidden input in apps/frontend/src/features/games/falling-words/view.tsx:59-69 has no tabindex management. When focus leaves it via Tab, the handleKeyDown handler in engine.ts no longer receives keyboard events. The "enter to restart" prompt in game-over.tsx is purely visual -- it relies on the hidden input being focused.

Suggested fixes (one of)

  1. Add tabindex={-1} to the hidden input to prevent Tab from leaving it
  2. Refocus the input when game-over or idle phase is entered
  3. Add a window-level keydown listener for Enter during game-over/idle phases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions