Skip to content

feat(rune-kit): submenu keyboard navigation and hover-open via MenuItem::on_submenu - #2204

Merged
opencodejr[bot] merged 1 commit into
devfrom
bot/issue-1387
Nov 25, 2026
Merged

opencodejr[bot] merged 1 commit into
devfrom
bot/issue-1387

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Refs #1387. This is the remaining submenu work after #1964.

What changed

  • New MenuItem::on_submenu(|s: &mut S, open| ..). It hands the menu the app's submenu open flag. Menus without it behave as before.
  • Keyboard (WAI-ARIA APG menu pattern):
    • Right, Return or Space on a submenu row opens the submenu and moves focus to its first item.
    • Left or Escape inside the submenu closes only the submenu and puts focus back on its row.
    • Right to left, Left opens and Right closes, matching the mirrored chevron and Rune's own focus navigation.
    • A submenu that flips sides only for lack of room keeps the keys.
    • Inside a modal menu (on_close), Escape in the submenu leaves the parent menu and its scrim open.
  • Hover: submenu rows and their siblings use the runtime's existing El::hover_delays (200 ms enter). Resting on a submenu row opens it; resting on any other row of the same menu, disabled rows included, closes it. The list of open-submenu closers is built once per menu and shared by its rows.
  • Closing with the menu:
    • Menu::on_close (Escape, a press outside) first closes every open controlled submenu, nested ones included, so the menu reopens with them closed.
    • Picking an item through on_select/on_select_tx does the same, except checkbox and radio items, which may keep the menu open.
    • An app that closes the menu any other way clears the flags itself. The on_submenu docs, README and doctest say so.
  • Core (rune crate): new Tx::key_direction(). In an El::on_key handler it gives the focused element's layout direction (set in element_key, Ltr elsewhere), so components can map Left and Right the way Rune's focus navigation does.
  • All on_submenu callbacks in one menu must take the same state type; this is documented.
  • Docs: the MenuItem paragraph in crates/rune-kit/README.md, plus a changelog fragment.

Testing

  • crates/rune-kit/tests/integration/menu_submenu_nav.rs:
    • Right/Left with focus, Return/Space/Escape.
    • A submenu flipped at the right window edge.
    • Right-to-left layout with swapped arrows.
    • A modal menu with on_close: Escape in the submenu closes only the submenu, the scrim stays, a second Escape closes the menu.
    • Escape on the menu and an outside press close the submenu, and the menu reopens with it closed.
    • An item pick closes the submenu; a checkbox pick keeps it open.
    • The hover delay, and a disabled row closing an open sibling.
  • cargo test -p rune-kit --test integration menu_: 23 passed.
  • RUNE_ALLOW_NO_GPU=1 cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid,rune/test-gpu-noop: all passed.
  • cargo lint: no errors and no warnings on changed lines.
  • cargo check -p rune --no-default-features --target wasm32-unknown-unknown and scripts/file-size.sh: pass.
  • Run on Linux x86_64, headless. No live window or screen reader.

Closes #1387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

0 participants