Menu (legacy)

Menu (legacy)

Menu is the Rust crate's older menu container: a <ul role="menu"> whose class list comes from the palette (hk-menu, plus inline / mode / compact / popover markers) and whose children are rows. MenuItem is one row and SubMenu is a collapsible group of rows. This page documents a legacy migration surface — it keeps existing Rust pages building; new surfaces should use the Vue menu, HkMenu.

MenuItem and SubMenu have no pages of their own; they are documented here with the container that contextualises them.

  • The shared name is the trap. HkMenu is a Vue-only cascading menu built on the dropdown surface; this Menu is an inline Rust list with its own row components, and nothing in Vue mirrors it.
  • Reach for it while migrating a Rust page that already renders this shape: a static, always-visible list of actions or links. For a menu that opens from a trigger, uses the Vue HkMenu; for a menu container with no rows of its own, the current MenuPanel.
  • The sub-state that a live menu needs — which row is active, which group is open — is closed over inside these components; the host can see none of it. Read the third section before depending on selection.

Import

rust
1
2
use hikari_components::*;          // Menu, MenuItem, SubMenu, MenuMode, MenuItemHeight
use hikari_components::prelude::*; // MenuProps, MenuItemProps, SubMenuProps, rsx!, VNode, Icon, MdiIcon

Each is a plain function taking its props struct: Menu(MenuProps { … }), MenuItem(MenuItemProps { … }), SubMenu(SubMenuProps { … }). The three props structs are in the prelude; MenuMode and MenuItemHeight are not. Every field has a default except MenuItem::height and SubMenu::height — those two declare no #[default], so an rsx! block for a row has to name a height (MenuItemHeight::Default or one of the two density variants).

Menu and SubMenu both take a children element. Write it bare (children: rsx! { … }) on Menu and on SubMenu; Some(…) around either is a type error.

The container, modes and density

Menu builds one class list on its <ul>: hk-menu, hk-menu-inline when inline, the mode class (hk-menu-vertical by default, hk-menu-horizontal under MenuMode::Horizontal), hk-menu-compact when compact, hk-menu-popover when in_popover, then class. The <ul> carries role="menu" and renders children verbatim — the container adds no rows, no dividers and no headings of its own.

default_active seeds a signal that no row reads, mode and compact are the two presentation switches, and glow / in_popover only travel through a context that MenuItem reads (see below). on_select is declared and never called: no row reports a selection to it.

Rust

Rows: MenuItem and SubMenu

MenuItem renders li.hk-menu-item[role="menuitem"] with data-key = item_key, the disabled flag as the (non-standard) attribute aria_disabled = "true" / "false", a click handler, and inside it a div.hk-menu-item-inner holding an optional span.hk-menu-item-icon around icon and a span.hk-menu-item-content around children. class is appended to the row's own classes and height adds one of hk-menu-height-default / -compact / -extra-compact.

A row's click runs only when it is not disabled: it calls onclick with the mouse event, then — if the row sits inside a Menu with request_close — calls that close callback. That is the one piece of menu-level behaviour a row participates in, and it exists for the popover case: a row pressed inside a popup closes the popup.

SubMenu renders li.hk-menu-submenu[role="none"] with data-key, a title band and a nested <ul role="menu">. The title band is a div (not a button) carrying the height class, the same aria_disabled attribute, the optional icon, a span with title and an Arrow glyph that points down while open and right while shut. A press on the title toggles a signal seeded from default_expanded unless the group is disabled. The nested list's visibility is written inline: display: block / none, opacity 1 / 0, translateX(0) / translateX(-8px), plus a fixed padding-left: 1em — and its aria-hidden follows the open state.

item_key and level are carried but not read for layout: nesting is the host's children, not level.

Rust

default_expanded defaults to false, so both groups above render their nested lists closed; set it to true (as the first group of the next example does) to see the rows. Re-closing is the user's press, which a snapshot never performs.

State the host cannot reach

Three pieces of state live inside these components and are not exposed:

  • the open groups. SubMenu owns its own signal; a press flips it and nothing reports the new value. A host cannot read whether a group is open, cannot open it from the outside, and cannot persist the choice.
  • the selection. Menu::default_active seeds a signal that no row reads, and MenuItem has no active prop and no active class: no row can look selected. on_select is never called, so the host has to own its own notion of "current row" and draw it in class or in the row's children.
  • the glow. MenuItem::glow and Menu::glow / Menu::in_popover decide whether the row is wrapped in a Glow chrome: should_glow is the row's own flag OR (the menu is in a popover AND the menu's glow is enabled). SubMenu's title always goes through the glow wrapper, and its wrapper also drops the block flag MenuItem's wrapper sets, so the two wrappers are not quite the same shape.

request_close is a Callback<()> on the menu that every enabled MenuItem calls after its own handler; SubMenu neither reads it nor passes it down, so a row inside a group does not close the menu.

Rust

The two groups differ only in default_expanded: the first renders its nested list with display: block, the second with display: none and aria-hidden="true". That flag is the whole of the difference — there is no animation and no measurement.

API

Rust

Props — Menu

PropTypeDefaultDescription
default_activeString""—
inlineboolfalse—
modeMenuModeMenuMode::Vertical—
compactboolfalse—
classString""—
childrenElement(empty)—
on_selectOption<EventHandler<String>>None—
in_popoverboolfalse—
glowboolfalse—
request_closeOption<Callback<()>>None—

Props — MenuItem

PropTypeDefaultDescription
item_keyString"".to_string()—
disabledboolfalse—
iconOption<Element>None—
childrenElementVNode::empty()—
classString"".to_string()—
levelu320—
heightMenuItemHeightMenuItemHeight::Default—
onclickOption<EventHandler<MouseEvent>>None—
glowboolfalse—

Props — SubMenu

PropTypeDefaultDescription
item_keyString""—
titleString""—
iconOption<Element>None—
disabledboolfalse—
default_expandedboolfalse—
levelu320—
heightMenuItemHeightMenuItemHeight::Default—
childrenElement(empty)—
classString""—

Accessibility

  • The container is a real ul[role="menu"], each MenuItem is a li[role="menuitem"], and a SubMenu is a li[role="none"] wrapping a title band and a nested ul[role="menu"]. The roles are in place, but nothing implements the behaviour they promise: no arrow-key navigation, no roving tabindex, no aria-activedescendant, no focus management, and no Menu-key handling. A keyboard user reaches the rows only if the host makes them focusable.
  • The SubMenu title is a div, not a button: it has no role, no tabindex and no keyboard activation, so a group can only be opened with a pointer. Its open state is not announced either — the nested list carries aria-hidden, but the title carries no aria-expanded and does not control an aria-controls target.
  • The disabled flag reaches the DOM as the attribute aria_disabled — an underscore, because that is how the render writes it — so assistive technology does not see aria-disabled at all; the row's click handler does check the flag, but the element stays focusable and nothing in the DOM states the state to a screen reader, so a disabled row is visually dimmed and otherwise silent.
  • The arrow glyph inside a SubMenu title is an inline SVG with no aria-hidden, so a screen reader may stop on it and announce nothing.
  • The glow wrapper inserts a div between the li and its content when a row glows; that is presentation only, but it is one more element to account for when the host styles rows by :first-child-style selectors.

Related components

  • HkMenu — the current menu, Vue-side: a cascading popup or an inline sidebar variant, and not a mirror of this component.
  • MenuPanel — today's menu container in both languages, when the list is a plain, always-open panel of rows.
  • MenuActionItem — the current row grammar for a menu action, with the icon cell and the states this surface lacks.
  • NavItem — a navigation row that picks its element from what the row is, if the list is routes rather than actions.