Menu
alikit:menu is an anchored, component-level dropdown built from public parts: a
trigger, a transparent modal popup, Menu_Item row owners, separators, optional ad-hoc
groups, and optional default row visuals. It owns roving Up/Down/Home/End navigation, checked and
disabled publication, Escape/outside dismissal, and trigger focus restoration. The application
owns items, command identity, checked state, custom rows, and dispatch.
Preview
Section titled “Preview”
Responsibility split
Section titled “Responsibility split”| Layer | Responsibility |
|---|---|
| Alicorn | Modal overlay containment, pointer/wheel/focus confinement, placement, Menu/Menu_Item roles, scroll region, buttons, theme roles. |
menu | Trigger, anchored popup, placement, active-row navigation, reveal, outside/Escape dismissal, checked/disabled/separator publication, group scaffolding, focus restoration. |
| Application | Items, command identity, dispatch, checked state, custom row content, and submenu composition. |
State keeps only ephemeral open/anchor/panel/scroll nodes, the active roving identity, focus
requests, and one chosen command key.
Copyable implementation
Section titled “Copyable implementation”Files: menu/menu.odin, menu/menu_test.odin, menu/menu_parts_test.odin,
examples/menu/main.odin, examples/menu_parts/main.odin,
examples/menu_composition/main.odin.
ITEMS: [3]menu.Item = { {key=1, label="Rename", shortcut="F2"}, {key=2, label="Show grid", checked=true}, {key=3, kind=.Separator},}
// In the ordinary root:_ = menu.trigger(ctx, &app.menu, "Actions", menu.Options{accessible_label="Actions"}, key=alicorn.key_string("actions-trigger"))
// In render_overlays:visible, chosen := menu.popup_begin(ctx, &app.menu, ITEMS[:], menu.Options{accessible_label="Actions"}, key=alicorn.key_string("actions-popup"), instance_id=1)if !visible { if chosen != 0 { app.run(chosen) } return}for item, index in ITEMS { if menu.item(ctx, &app.menu, item, index) { app.run(item.key) }}menu.popup_end(ctx, &app.menu)A custom trigger calls open_from_node(&state, runtime, trigger_node).
Parts and identities
Section titled “Parts and identities”| Part | Identity | What can be omitted or replaced |
|---|---|---|
| Trigger | application key | Stock Button; custom triggers use open_from_node. |
| Popup | menu_semantic_id(instance_id) | Transparent overlay, panel, Menu group, row scroll. |
| Row | item_semantic_id(instance_id, item_key) | item_begin/item_end owns Menu_Item; draw any content. |
| Row surface | stable child key | row_surface optional. |
| Check/label/shortcut/detail | stable child keys | Optional default visuals; custom rows omit them. |
| Separator | no identity | Visual row, skipped by navigation. |
| Group | group_semantic_id(instance_id, key) | Optional ad-hoc nested Menu group; not a collection. |
item() is a convenience wrapper over item_begin, row_surface, check, label, shortcut,
and item_end. A custom row keeps the semantic owner and can render a label/detail/shortcut,
checked mark, icon, or any ordinary Alicorn layout.
Groups and submenus
Section titled “Groups and submenus”Alicorn’s pinned semantic_collection_begin still rejects .Menu, so groups publish ad-hoc nested
Menu semantics without a count (#241 remains open). Groups are single-level and do not add
navigation slots.
Submenus are not implemented in v1. The single overlay, panel scroll, active-row index, and trigger
focus restoration do not contain a nested open/parent-focus coordination model. Applications that
need a submenu compose a second menu State; the package does not duplicate overlay policy.
Styling, motion, and theme
Section titled “Styling, motion, and theme”Recipe has optional panel, item, and active-item surface roles plus a core check color. Style
carries corner radius, focus width, and check slot width. Options carries popup width, row
height, padding, maximum visible rows, placement margin, and keep_open_on_select. The popup uses a
transparent backdrop and a themed surface panel. Keyboard-active rows are revealed through an inner
hidden-scrollbar scroll region. There is no component motion.
Keyboard and accessibility contract
Section titled “Keyboard and accessibility contract”| Input | Result |
|---|---|
| Trigger activation | Open/close; publishes Expanded while open. |
Up / Down | Move the active row, skipping separators and disabled rows. |
Home / End | First/last enabled row. |
Return / Space | Choose the active row and close (unless keep_open_on_select). |
Escape | Close and restore trigger focus. |
| pointer | Row activation; outside pointer down dismisses. |
Rows publish Menu_Item with label, value, description, Checked/Disabled/Current, and
Focus/Select/Press when enabled. The popup publishes one Menu with the accessible label.
Not claimed: submenus, type-ahead, multi-select, composite menu collection count/position, or native menu integration.
Conformance tests
Section titled “Conformance tests”menu/menu_test.odin covers the default wrapper: identities, theme contract, trigger semantics,
checked/disabled states, navigation and activation, Escape/focus restoration, pointer selection,
outside dismissal, bottom-edge placement flip, and viewport containment.
menu/menu_parts_test.odin covers custom rows, groups, keyboard/pointer/escape/outside paths, and
placement.
odin test menu -define:ODIN_TEST_THREADS=1 -collection:alicorn=<alicorn> -collection:alikit=../out/menu_example.exe --smoke./out/menu_parts_example.exe --smoke./out/menu_composition_example.exe --smokeThere is no dropdown-menu pattern kind in testui; explicit drive assertions are used.
API reference
Section titled “API reference”| Declaration | Notes |
|---|---|
Item / Item_Kind | Command identity, label/detail/shortcut, .Item or .Separator, disabled/checked. |
Options | Popup geometry, max visible rows, placement margin, keep_open_on_select. |
Recipe / Style | Optional surface roles and visual geometry. |
State / MenuItem | Retained popup state and per-description row context. |
Event | Pending chosen command key. |
trigger, popup_begin, popup_end | Anchored shell. |
item_begin, item_end, separator, group_begin, group_end, item | Row/group parts and convenience. |
row_surface, check, label, shortcut, detail | Optional default visuals. |
open_from_node, close, take_chosen | Custom trigger, close, pending key. |
menu_semantic_id, item_semantic_id, group_semantic_id | Stable semantic identities. |
Limits
Section titled “Limits”- Headless tests do not prove a physical screen-reader menu session or pixels.
- Long menus scroll inside the popup but do not use a composite collection.
- Submenus are application-composed from a second
State. - Menu groups are ad-hoc nested semantics, not a counted collection.
Compatibility
Section titled “Compatibility”47c9d4a7cd1f637876190fec899daeeac00a30ae. See
Compatibility and pinning.