Components
Menu
A button that opens a menu, or a context menu from a right-click or long press, with your own trigger, a header, icons, groups, destructive items, checkbox and radio items, submenus, a bottom sheet on phones, and a menubar of menus.
Import
import { Menu, MenuTrigger, MenuContextTrigger, MenuContent, MenuItem, MenuCheckboxItem, MenuRadioGroup, MenuRadioItem, MenuSub, MenuSubTrigger, MenuSubContent, MenuSeparator, MenuHeader, Menubar } from '@rinzai/zen';Examples
Actions
The usual "⋯" menu of actions for one thing: an icon button as the trigger, and a destructive item last.
Context
Right-click an entry (or press and hold on a phone) for its actions. One menu serves the whole list.
- Weekly shop−$165
- Train pass−$92
- Salary+$4,200
Options
Settings that stay put while you change them: checkbox items turn columns on and off, radio items pick the order, and a submenu holds the less used exports. Hover, or use the arrow keys, to open it.
Sheet
A song's menu: on a phone (narrow the window), a bottom sheet, its playlists sliding in over it.
Bar
A row of menus, as at the top of an app. Tab to it once: ←→ move between the menus and ↓ opens one; with one open, ←→ go to the next and pointing at another label switches to it.
API reference
<Menu>
A list of actions that opens from a button: a native popover, so outside clicks and Escape close it and focus returns to the button. Arrow keys, Home and End move between items. Put a MenuTrigger (its content is yours: an icon, an avatar, a label) and a MenuContent inside; fill the content with MenuItem, MenuSeparator and MenuHeader. For a context menu, put a MenuContextTrigger around what it's for instead of a MenuTrigger.
| Prop | Type | Default |
|---|---|---|
onOpenChangeEvery open and close: the trigger, choosing an item, outside clicks, Escape. | ((open: boolean) => void) | — |
<MenuTrigger>
The button that opens the menu (↓ or ↑ opens it at its first or last item). Give it an aria-label when it shows only an icon or avatar; the menu is named after it. In a Menubar it's one of the bar's items, and looks it. With asChild, your own button instead.
| Prop | Type | Default |
|---|---|---|
asChildPut the trigger's props on your own button element instead of rendering one. | boolean | — |
<MenuContextTrigger>
What a context menu is for, e.g. a row or a card: right-click (or the keyboard's menu key, or Shift+F10) opens the Menu where the pointer is, and so does a long press on a phone. While its menu is open it has data-popup-open, to show what the menu is for. With asChild, your own element instead of a div.
| Prop | Type | Default |
|---|---|---|
asChildPut its props on your own element (the single child) instead of a div. | boolean | — |
disabledLeave the browser's own context menu. | boolean | — |
<MenuContent>
The menu panel: glass, below the button (above it if there's no room), lined up with its end edge by default (its start edge in a Menubar). A context menu opens from the pointer instead; name it with aria-label.
| Prop | Type | Default |
|---|---|---|
alignWhich edge of the button the menu lines up with (default end; a context menu starts at the pointer), or centred on it. | "center" | "end" | "start" | — |
offsetGap between the button and the menu, in px. | number | — |
sheetOn phones (below | boolean | — |
<MenuItem>
One choice in a Menu: closes the menu, then runs onSelect. An icon sits before the label (muted, or red with the label when tone is negative). With asChild, the item's role and styles go onto your own element instead, such as a router's Link.
| Prop | Type | Default |
|---|---|---|
asChildPut the item's role and styles on the single child element (a link) instead of a button. | boolean | — |
iconShown before the label; size it yourself (e.g. size-4). | ReactNode | — |
onSelectRuns after the menu closes. | (() => void) | — |
tone
| "default" | "negative" | default |
<MenuCheckboxItem>
A choice that's on or off, e.g. a column to show: choosing it flips checked and leaves the menu open, so several can be set at once. A tick shows while it's on.
| Prop | Type | Default |
|---|---|---|
checkedOn (ticked); give it to control the item, or | boolean | — |
defaultChecked | boolean | false |
onCheckedChange | ((checked: boolean) => void) | — |
<MenuRadioGroup>
One choice out of several, e.g. how to sort: put MenuRadioItems inside. Choosing one leaves the menu open.
| Prop | Type | Default |
|---|---|---|
defaultValue | string | null | null |
onValueChange | ((value: string) => void) | — |
valueThe chosen item's | string | null | — |
<MenuRadioItem>
One of a MenuRadioGroup's choices; a dot marks the chosen one.
| Prop | Type | Default |
|---|---|---|
valueRequired | string | — |
<MenuSub>
A menu inside a menu, opening beside its item: on hover, or with Enter, Space or the arrow towards it; the arrow back (or Escape) closes it. Put a MenuSubTrigger and a MenuSubContent inside, in a MenuContent.
| Prop | Type | Default |
|---|---|---|
onOpenChangeEvery open and close: the trigger, choosing an item, outside clicks, Escape. | ((open: boolean) => void) | — |
<MenuSubTrigger>
The item a submenu opens from; a chevron after its label points the way.
| Prop | Type | Default |
|---|---|---|
iconShown before the label; size it yourself (e.g. size-4). | ReactNode | — |
<MenuSubContent>
The submenu's panel, beside its item (on the other side if there's no room), its first item level with it.
| Prop | Type | Default |
|---|---|---|
offsetGap between the item and the submenu, in px (counting the menu's own padding). | number | 8 |
<MenuSeparator>
A hairline between groups of items.
| Prop | Type | Default |
|---|---|---|
className | string | — |
<MenuHeader>
Content at the top of a menu that isn't a choice, e.g. who is signed in.
No props of its own; it accepts the props of the element it renders.
<Menubar>
A row of menus, as at the top of an app (File, Edit, View): put a Menu for each inside, its MenuTrigger a label. One Tab stop: ←→ move between the menus, ↓ or Enter opens one; while one is open, ←→ open the one beside it and pointing at another switches to it. Name it with aria-label.
No props of its own; it accepts the props of the element it renders.