Skip to content

Fix TUI focus ring and key routing - #30

Merged
archlemon merged 1 commit into
mainfrom
fix/tui-focus
Nov 28, 2026
Merged

archlemon merged 1 commit into
mainfrom
fix/tui-focus

Conversation

@archlemon

Copy link
Copy Markdown
Member

Summary

Fixes #26, from the TUI audit.

  • Focus is held by ID. tuiFocusManager tracked a cursor index. When the focused button left the view, focus silently moved to the control that shifted into its slot, and Enter activated it. Focus now stays on the same control wherever it moves, and clears if that control leaves.
  • Disabled controls. Disabled Input and TextArea no longer join the Tab ring (they used to accept typing).
  • Controls without an ID. A Checkbox without an ID is no longer a dead Tab stop, and a control with ID "" no longer renders as focused (and gets a live cursor) while nothing has focus.
  • Visible Responsive variant. focusable now carries the input or text-area element, so key routing edits the control the ring found: the visible Responsive variant. Previously findInputByID searched every variant and Enter dispatched a hidden variant's OnSubmit. formValues reads the visible variant too. The now-unused findInputByID/findAreaByID are removed.
  • Duplicate labels. Buttons sharing a label without IDs get unique focus keys (btn:Delete, btn:Delete#2), numbered identically by the ring and the renderer. Enter on the second button now runs its own OnClick.
  • Select clicks. Clicking a Select inside a Form cycles the Select; it used to submit the form.
  • Perf. A keystroke with an input focused built the View 5 times; now it builds it twice (route, then render).

Test plan

  • New focus_ring_test.go, one test per item above. Six of the seven fail on main (for example "focus slid onto btn:c", "Enter dispatched narrow at width 80", "built the view 5 times"). The Select-click test can't build against main because it uses the new fields.
  • go test -race ./..., go vet ./..., GOOS=js GOARCH=wasm go vet .

- Focus is held by ID: when the focused control leaves the view focus
  clears instead of sliding onto whatever shifted into its slot.
- Disabled inputs and text areas, and checkboxes without an ID, stay
  out of the Tab ring; a control without an ID never renders as
  focused.
- Key routing edits the input or text area the focus ring found,
  which is the visible Responsive variant, instead of looking the ID up
  again across every variant. formValues reads the visible variant
  too.
- Buttons sharing a label get unique focus keys (#2, #3), so Enter on
  the second runs its own OnClick.
- Clicking a Select cycles it instead of submitting its form.
- A keystroke builds the View twice instead of five times.

Closes #26
@archlemon
archlemon merged commit e1c7b23 into main Nov 28, 2026
2 checks passed
@archlemon
archlemon deleted the fix/tui-focus branch November 28, 2026 07:01
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.

TUI focus ring and key routing bugs

1 participant