Menu
HkMenu is the library's cascading menu: give it one entry per action (and children on the ones that branch) and it renders a menu — an anchored popout on desktop, a stack of bottom sheets on mobile — one level at a time, with the deep levels anchored to the row that opened them. The presentation is not this component's own: every level renders through HkSelectPanel, the same dropdown surface the library's selects use, so outside-click closing, Escape, the popup z-stack and the per-level back-guard entry are shared rather than re-implemented.
- Its other variant, variant="sidebar", is not a popup at all: it is an inline vertical nav list with collapsible groups, for a drawer or a settings rail with nothing to open.
- The rows are drawn by this component; the single-row grammar belongs to MenuActionItem (an action row), MenuIdentityItem (a person / workspace header row) and MenuSection (a captioned run), and the plain container those rows live in is MenuPanel.
- The Rust crate's Menu shares this page's name and is a different component: see Menu (legacy).
Import
;
HkMenu is Vue-only — the Rust crate has no mirror of it (its Menu is the legacy container). The public HkMenuItem type is exported beside the component.
Items, cascade and the active row
An item is { key, label, icon?, iconNoScale?, flag?, checked?, disabled?, danger?, badge?, children? }. icon is a component, not a name (pass the imported glyph, e.g. Settings), drawn at 16px in the row's icon cell; iconNoScale marks a glyph whose size carries meaning (a status dot) so the sidebar's rail flip travels it without tweening it. badge is a right-aligned count pill and only the sidebar variant renders it. An item with a non-empty children is a branch, not an action.
open is required and controlled: the menu renders the panel tree while it is true and stays mounted for one leave window (320ms) after it flips false, so the panels can animate shut. A close — an outside click, Escape, a leaf selection — emits update:open with false; the host writes the value back. A leaf press also emits select with the item's key and the item itself.
checked opts a level into the leading check column: checked: true draws the mark, a false item draws an empty placeholder so labels stay aligned, and "auto" reserves the column only when some item of that level sets checked at all. A plain action menu therefore shows no check column.
activeKey (sidebar variant) marks the current row; groups containing it open by themselves on mount, so a fresh sidebar shows where you are.
The sidebar variant is the part of HkMenu that renders without an anchored surface, so it is what the preview shows. An item with checked set renders the check cell (the Check glyph above is the same mark); both checked values draw the column.
Anchoring, placement and the panel cap
The popup variant is never rendered inline: HkMenu renders HkSelectPanels, and each one teleports itself to the document body. That has three consequences:
- the host must supply an anchor. anchorRef is an { getBoundingClientRect(), contains() } object — real elements qualify, and so does a synthetic anchor. With null the panel has no placed side to hang from and is only clamped into the viewport, so pass an anchor whenever the menu hangs off a trigger.
- placement picks the base side (bottom-start by default, plus the other *-start sides) and offset the gap (6px by default); autoFlip (default true) moves a panel whose placed side cannot host it to the opposite vertical side, and matchAnchorWidth makes the popout take the anchor's width.
- maxHeight caps the desktop popouts of every level (a CSS length such as min(18rem, 45dvh)); the mobile sheets ignore it because a sheet hugs its content up to the family's 80%-of-viewport ceiling. aboveChrome teleports the panels to the top root so a menu whose trigger lives on a window caption band paints above the band instead of under it.
Because the popout is teleported, an example of the popup variant shows nothing in its own box: the card captures its own subtree, and the panels are not in it — on the docs site they paint over the page instead. The examples on this page stay on the sidebar variant, which renders inline, and exercise the same item model.
defaultExpandGroups turns the accordion into a table of contents — every group starts open and only a user collapse closes one. collapsed switches the sidebar to its icon-rail mode: rows become centred icon buttons whose label lives in a tooltip, badges degrade to a corner dot, and a group header becomes a caret row that still opens its children recursively. An icon-less leaf falls back to its label's first character, so no destination disappears behind a missing glyph.
Slots: header, pinned header and before-item
The root level takes three slots.
- header is a scrolling band above the rows, inside the panel's scroll region — the place for a section label or an identity card.
- pinnedHeader is chrome that must not scroll: forward a live-filter search field here and the list scrolls under it instead of taking it along.
- before-item is scoped ({ key }) and is called right before each root row; its nodes are spliced in as that row's immediate predecessors, with no wrapper and no divider, so the host supplies the row markup. It exists for the one-off row that must sit directly above another one — an account action above "Log out". It is inert in cascade levels, in mobile sub-sheets and when a default slot replaces the item model.
Cascade levels and mobile sub-sheets carry neither header nor pinnedHeader.
The sidebar variant reads the same header slot — its own band above the rows, with the same wrapper class — so an account menu keeps one grammar whether it pops up on desktop or sits in a drawer. pinnedHeader and before-item belong to the popup variant's root level only; the sidebar ignores them.
Behaviour the panel machinery hands you
Several behaviours follow from rendering through HkSelectPanel rather than from anything HkMenu does itself:
- Desktop cascade. A branch press opens (or switches to) a nested panel anchored to that row — to its right, flipping left when the viewport runs out. Hovering a sibling branch switches the open submenu to it; hovering a row at a level collapses everything deeper. Leaf presses emit select and close the menu.
- Mobile sheets. Below the library-wide 768px breakpoint every level, the root included, docks as its own bottom sheet with a scrim, a grabber and the panel title. Each level owns one back-guard history entry, so the system back gesture closes exactly one level.
- Outside clicks are attributed by depth. A capture-phase listener records the deepest menu level a click landed in, and a panel's own close request is ignored while the click clearly belongs to a deeper panel — the panels are teleported siblings, not nested DOM, so the shallow ones would otherwise tear down under the deep one.
- A leaf press cancels the back-guard rewind before closing, because an async navigation must not be bounced back by the deferred history.go(-n).
mobileBreakpoint is kept for API compatibility and no longer decides anything — the shared panel surface owns that decision. title names the sheet's header and the popout's accessible name; collapsed, defaultExpandGroups and activeKey are sidebar-only.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| variant | <code>String as PropType<"popup" | "sidebar"></code> | "popup" | — |
| activeKey | String | undefined | — |
| title | String | "" | — |
| items | Array as PropType<HkMenuItem[]> | — | ✓ |
| open | Boolean | — | ✓ |
| anchorRef | <code>Object as PropType<PanelAnchor | null></code> | null | — |
| placement | <code>String as PropType< "bottom-start" | "bottom-end" | "top-start" | "top-end" | "right-start" | "left-start" ></code> | "bottom-start" | — |
| mobileBreakpoint | Number | 768 | — |
| offset | Number | 6 | — |
| selectMode | <code>[String, Boolean] as PropType<"auto" | boolean></code> | "auto" | — |
| matchAnchorWidth | Boolean | false | — |
| maxHeight | String | undefined | — |
| autoFlip | Boolean | true | — |
| defaultExpandGroups | Boolean | false | — |
| collapsed | Boolean | false | — |
| aboveChrome | Boolean | false | — |
Emits
| Event | Payload |
|---|---|
| update:open | — |
| select | — |
Accessibility
- The popup variant's levels are HkSelectPanels: the root takes title as its accessible name, a cascade level takes the name of the branch row that opened it, and a mobile sheet takes the row's label as its header. Without a title the desktop popout is unnamed.
- HkMenu renders its rows as plain buttons (button.hk-menu-row) inside that panel — not as a role="menu" / role="menuitem" structure. The panel supplies the container semantics (a dialog on mobile sheets, with the title as its name) but no menu arrow-key navigation, so do not promise Menu-key behaviour: rows are reached with Tab.
- The sidebar variant is a <nav> named by title (falling back to the literal "menu"). Its rows are buttons, and its group toggles are buttons carrying aria-expanded and aria-haspopup="true" — the open/closed state is announced, and the fold is a height transition that honours reduced-motion and the global animation switch.
- In rail mode every row takes its label (plus the badge count) as aria-label through a tooltip, and the active row also carries aria-current="page", so an icon-only column stays readable.
- checked on a sidebar row draws a check cell that is aria-hidden; the state is not stated in the row's accessible name, so pair a visual check with wording in the label when the state matters.
- A disabled row is a natively disabled button; danger is colour only, so a destructive row needs wording that says so.
Related components
- Menu (legacy) — the Rust Menu / MenuItem / SubMenu: same name, a different, non-mirrored component.
- MenuPanel — the plain menu container both languages ship, for a menu that is always open.
- MenuActionItem, MenuIdentityItem, MenuSection — the rows and the captioned run this menu's grammar is built from.
- NavSidebar and NavItem — the navigation band and row, when the list is routes rather than actions.