Skip to content

Roving arrow keys for groups on the page; radio_group on them (#346, PR 1) - #368

Merged
samitbasu merged 2 commits into
mainfrom
roving-346
Nov 18, 2026
Merged

samitbasu merged 2 commits into
mainfrom
roving-346

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #346: PR 1 of the design note, the core roving nav that the tabs widget will build on.

What changes

  • NodeHandle::nav(Nav) makes a node on the page a group whose items the arrow keys move the focus through, as overlays already do.
    • The items are the nodes under the group that have an item role and sense input. A disabled item is skipped.
    • The group is one Tab stop: the item that has the focus, or else the one marked selected, or else the first enabled item. The other items are left out of the Tab order.
    • The stop is settled before the frame's widgets are drawn. The arrow keys move the focus first, so the item they reach can take the focus in that same frame.
  • Two new Nav variants on one engine. They share the item collection, the Tab-stop rule and the focus moves; only the key table differs.
    • Nav::Row(Wrap): ←/→ move, and Home/End go to the ends. ↑/↓ are left alone. For a tab list.
    • Nav::Radio(Wrap): all four arrows move, ↓/→ forward and ↑/← back, and Home/End are left alone. This is exactly the radio group's behaviour today.
    • Both also work on an overlay.
  • NodeHandle::selection_follows_focus() on a group: an arrow that moves the focus to an item also activates it, as a click would. It goes through the same pending activation that Enter on a listbox uses, so on_click runs. Without it, the arrows only move the focus, and Enter or Space activates the item, as egui does for any focused clickable.
  • NodeHandle::selected(Mark) marks the chosen item of its group, which makes that item the Tab stop while the focus is elsewhere. It is announced as its role says: a tab as selected, a radio button as checked.
  • Tab and RadioButton are item roles (Nav's doc lists them).
    • An overlay's items no longer include those of a group nested inside it, which belong to the group.
    • Focus on a tab or a radio button doesn't show as its hover look, as it does on a menu item; they draw the focus ring.
  • Problem::NavNeedsOverlay: nav(Nav::Listbox(..)) or nav(Nav::Submenu(..)) on a page node is reported, and the node is not a group. Nav::None makes no group.
  • radio_group now uses the engine.
    • The circles are RadioButton items marked selected, and the column is a Nav::Radio(Wrap::Around) group with selection_follows_focus().
    • Its private roving copy is deleted: navigate, take_focus_if_asked and the egui-temp FOCUS_REQUEST workaround. The workaround is no longer needed, because the item an arrow reaches is the Tab stop in that same frame.
    • The column is now an identified node at the group's own key path (div_id_with on its slot, where before an anonymous div sat under a claimed key). The circles' paths and ids are unchanged.

Breaking changes

  • Nav gained Row and Radio, so an exhaustive match on Nav outside the crate needs two more arms.
  • Problem is #[non_exhaustive], so NavNeedsOverlay breaks nothing.

Behaviour

Radio's behaviour is unchanged (it was declared behaviour-preserving): every existing test passes unmodified, and no golden changed.

Decisions

Picked by the user:

  • Nav::Row(Wrap) for tabs and toolbars, plus Nav::Radio(Wrap) for radio, on one engine (option (a)). The note's Row alone would have dropped radio's ↑/↓.

Decided by default, for review:

  • New, not in the note: selection_follows_focus() (the WAI-ARIA term), a group method. Radio uses it, and the tabs widget will use it for activation on focus and leave it off for .activate_on_enter().
  • New, not in the note: the stop rule prefers the focused item while focus is inside the group. Otherwise, with .activate_on_enter(), the tab an arrow reached would not be focusable and egui would drop the focus. Leaving the group and coming back with Shift+Tab lands on the selected item, as the APG tabs pattern says.
  • New, not in the note: selected(Mark) and not selected(bool), because of the no-naked-bool rule, and Mark is what the owned widgets already pass.
  • New, not in the note: on a radio button, selected sets accesskit's checked state (toggled), not selected, which ARIA doesn't define for radios.
  • New, not in the note: Nav::Menu and Nav::Grid are accepted on a page group too, with real focus and one Tab stop. Only Listbox and Submenu, which need an overlay, are refused.
  • New, not in the note: a text field inside a group keeps Home and End, as in an overlay.

Tests

New in tests/it/roving.rs, all built on the public API alone and driven by kittest key events through the real dispatch:

  • the_list_is_one_tab_stop_on_the_selected_item
  • with_nothing_selected_the_first_enabled_item_is_the_tab_stop
  • left_and_right_move_the_focus_and_wrap_and_home_and_end_go_to_the_ends (the selection does not move)
  • up_and_down_do_nothing_in_a_row
  • a_row_that_stops_stays_on_its_ends
  • the_arrows_skip_a_disabled_item
  • tab_leaves_from_the_focused_item_and_comes_back_to_the_selected_one
  • enter_and_space_activate_the_focused_item
  • when_selection_follows_focus_an_arrow_activates_the_item_it_reaches (entering the group activates nothing; one activation per key)
  • a_radio_nav_moves_on_all_four_arrows_and_leaves_home_and_end_alone
  • the_selected_tab_is_announced_as_selected
  • a_listbox_nav_on_a_page_node_is_reported_and_makes_no_group
  • in_a_menu::the_menus_arrows_pass_over_a_group_inside_it

The radio group's existing tests pass unchanged: owned_choice (one Tab stop on the chosen option, all four arrows, Shift+Tab back), and choices (disabled options skipped, wrapping).

Reversion check: on main the new suite doesn't compile, because the API is new. Each mutation below fails tests, and the unmutated branch passes them all:

  • the stop rule ignores the focused item: 10 fail (radio's owned_choice and choices too);
  • selection_follows_focus ignored: 4 fail (radio's three, plus one roving);
  • a row also takes ↑/↓: 1 fails;
  • Radio takes Home/End: 1 fails;
  • a nested group's items counted as the overlay's: 1 fails;
  • disabled items not skipped: 3 fail;
  • the non-stop items left in the Tab order: 10 fail;
  • selected not announced: 1 fails;
  • radio's circle ignores the activation an arrow sends: 3 fail (all radio).

Wording for you to check: the existing Nav doc now lists Tab and RadioButton among the item roles, and says it also applies to a group on the page.

TODO(prose)

NodeHandle::nav, NodeHandle::selection_follows_focus, NodeHandle::selected, Nav::Row, Nav::Radio and Problem::NavNeedsOverlay are one-liners or short drafts for you to rewrite.

There's no UI change, so there is nothing to try by hand. The tabs widget (PR 3) and its gallery (PR 4) get the trial.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o

samitbasu and others added 2 commits November 18, 2026 10:08
A group on the page is declared with `NodeHandle::nav(Nav)`. The arrow
keys move real focus through its items, which are the nodes under it that
have an item role, now including `Tab` and `RadioButton`. The group is one
Tab stop: the focused item, else the one marked `NodeHandle::selected`,
else the first enabled one. The stop is settled before the widgets are
drawn, so the item an arrow reaches can take the focus in the same frame.

`Nav` gains `Row(Wrap)` (Left and Right, Home and End: a tab list) and
`Radio(Wrap)` (all four arrows, no Home or End: a radio group). They run
on one engine with the overlay's key tables. `selection_follows_focus()`
makes an arrow activate the item it reaches, through the pending
activation that Enter on a listbox uses.

radio_group now uses the engine. Its private roving code is deleted
(`navigate`, `take_focus_if_asked` and the FOCUS_REQUEST workaround).
Behaviour-preserving: its tests pass unchanged, and no golden changed.

Behaviour changes:
- An overlay's items no longer include a nested group's items.
- `Nav::Listbox` or `Nav::Submenu` on a page node is reported as
  `Problem::NavNeedsOverlay`, and the node is no group.

Breaking: `Nav` has two new variants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user (2026-11-18). Gate (my run with current main): cargo xtask ci exits 0. Merging.

@samitbasu
samitbasu merged commit d4e971b into main Nov 18, 2026
4 checks passed
samitbasu added a commit that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
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.

1 participant