Menu
Menu opens a floating list of actions from a button, such as Rename or Delete for a file.
<Menu> <MenuTrigger render={<Button>Actions</Button>} /> <MenuContent> <MenuGroup> <MenuLabel>File</MenuLabel> <MenuItem trailing={<Kbd>⌘D</Kbd>}>Duplicate</MenuItem> </MenuGroup> <MenuCheckboxItem defaultChecked>Show hidden</MenuCheckboxItem> <MenuRadioGroup defaultValue="name"> <MenuRadioItem value="name">Sort by name</MenuRadioItem> </MenuRadioGroup> <MenuSub> <MenuSubTrigger>Export as</MenuSubTrigger> <MenuSubContent> <MenuItem>PNG</MenuItem> </MenuSubContent> </MenuSub> </MenuContent></Menu>A Menu opens a floating list of actions when someone presses its trigger. Each row is one action, and choosing a row runs it and closes the menu. Use a Menu when the choices are things to do. Use a Select to choose a value in a form, a ContextMenu for actions that open at the pointer on a right-click, and a Popover for a floating panel that holds other content, such as a short form.
A row can show an icon in leading and a keyboard shortcut in trailing, and tone="destructive" marks an action that deletes something. Checkbox rows and radio rows show a setting's current state, and a submenu holds a related set of choices. Put a <Separator> between groups of rows. Rows without an icon still line up with rows that have one, because the space for the icon is always kept.
Set size on the Menu to size the rows, icons and text in the panel, and give the trigger button the same size. The panel follows the theme: in a raised theme it casts a shadow, in a flat theme it shows a thin edge instead, and with a glass material it uses glass.
Enter or Space on the trigger opens the menu. The arrow keys move between rows, typing a few letters jumps to the row that starts with them, and Escape closes the menu and returns focus to the trigger. The arrow key that points in the reading direction opens a submenu. Screen readers announce the menu, each row, and whether a checkbox or radio row is checked.
The part names follow shadcn/ui's dropdown menu (MIT), and the behaviour comes from Base UI's Menu.
- Select when the person picks a value, and the value stays shown.
- Context Menu when the actions open from a right-click or long press on an area. Every action in it must also be reachable another way, because nobody can see that it exists.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Opening the menu
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | A <MenuTrigger> and a <MenuContent>. |
defaultOpen? | boolean | Uncontrolled starting state. |
onOpenChange? | (open: boolean, details: MenuOpenChangeDetails) => void | Fires on every open and close, controlled or not, including the dismissals the menu handles itself: Escape, an outside press, and choosing a row. |
open? | boolean | Controls whether the menu is open. |
size? | "1" | "2" | "3" | "4" | The size step of the menu. |
MenuTrigger
The button that opens the menu. Pass your own <Button> to render, so the trigger is a real Kookie button
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The label of the trigger. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
disabled? | boolean | Turns the trigger off, so the menu cannot open. |
nativeButton? | boolean | Tells the trigger whether the rendered element is a real <button>. |
render? | RenderElement | Usually a Kookie Button: <MenuTrigger render={<Button/>}>Open</MenuTrigger>. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
Presenting the panel
MenuContent
The floating panel that holds the rows. It opens next to the trigger, above the rest of the page, with the same theme as the trigger
| Prop | Type | What it does |
|---|---|---|
align? | "start" | "center" | "end" | How the menu aligns along that edge. |
children? | React.ReactNode | The rows of the panel: MenuItem, MenuCheckboxItem, MenuRadioGroup, MenuGroup, MenuLabel and MenuSub. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
side? | "top" | "bottom" | "left" | "right" | The edge of the trigger that the menu opens from. |
sideOffset? | number | The distance from the trigger, in pixels. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
Listing actions
MenuItem
One action row, with optional leading and trailing content. It lights up when the keyboard or the pointer reaches it
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The row's words, which are the verb. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
closeOnClick? | boolean | Close the menu when this item is chosen. |
disabled? | boolean | Turns the row off, so it cannot be chosen. |
label? | string | Typeahead text when children aren't plain text. |
leading? | React.ReactNode | Content at the start of the row, usually an icon. |
onClick? | React.MouseEventHandler<HTMLElement> | Runs when the user chooses the row. |
render? | RenderElement | Renders the row as a different element, such as an <a href> or your framework's link. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
tone? | "destructive" | Marks the row as a dangerous action, such as delete. |
trailing? | React.ReactNode | The tail of the row: a <Kbd> shortcut hint, a count, a state glyph. |
Grouping into sections
MenuGroup
A set of related rows. When a MenuLabel is inside it, screen readers use the label as the group's name
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The rows of the group, and at most one MenuLabel that names them. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
MenuLabel
A heading above a set of rows. It lines up with the rows, but people can't choose it. Use it inside a group or on its own
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The heading's words: what the rows beneath it have in common. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
Rows that show a state
MenuCheckboxItem
A row that turns a setting on or off. A tick in the accent colour shows when it is on, and its space is kept when it is off, so the rows stay aligned
| Prop | Type | What it does |
|---|---|---|
checked? | boolean | Controls whether the row is ticked. |
children? | React.ReactNode | The text of the row. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
closeOnClick? | boolean | Close the menu when this row is chosen. |
defaultChecked? | boolean | Uncontrolled starting state. |
disabled? | boolean | Turns the row off, so the user cannot change it. |
label? | string | Typeahead text when children aren't plain text. |
onCheckedChange? | (checked: boolean) => void | Fires with the row's new state on every toggle, controlled or not. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
trailing? | React.ReactNode | Content at the end of the row, such as a shortcut hint or a count. |
MenuRadioGroup
Holds the one chosen value for a set of radio rows. Use value and onValueChange to control it, or defaultValue to let it hold the value
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The MenuRadioItem rows, and at most one MenuLabel that names the choice. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
defaultValue? | string | Uncontrolled starting choice. |
disabled? | boolean | Turns off every row in the group. |
onValueChange? | (value: string) => void | Fires with the newly chosen value. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
value? | string | Controls the chosen value. |
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The text of the row. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
closeOnClick? | boolean | Close the menu when this row is chosen. |
disabled? | boolean | Turns the row off, so it cannot be chosen. |
label? | string | Typeahead text when children aren't plain text. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
trailing? | React.ReactNode | Content at the end of the row, such as a shortcut hint or a count. |
value | string | The value that the row sets when the user chooses it. |
Nesting a menu
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | A MenuSubTrigger and a MenuSubContent. |
defaultOpen? | boolean | Uncontrolled starting state. |
onOpenChange? | (open: boolean, details: MenuOpenChangeDetails) => void | Fires on every open and close of this submenu, including the ones it handles itself (the pointer leaving its row, Escape, choosing a row inside it). |
open? | boolean | Controls whether this submenu is open. |
MenuSubTrigger
The row that opens a submenu. It stays highlighted while the submenu is open, and its chevron points the way the submenu opens
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The text of the row. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
disabled? | boolean | Turns the row off, so the child menu cannot be opened. |
label? | string | Typeahead text when children aren't plain text. |
leading? | React.ReactNode | Content at the start of the row, usually an icon. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
MenuSubContent
The submenu's panel. It opens beside its trigger row, with its first row level with that trigger
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The rows of the submenu. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
emphasison rows — Every row in a menu is an equal choice, so there is nothing to make louder or quieter. Order the rows and word them clearly instead, and usetone="destructive"for a dangerous action.- A Shortcut part — To show a keyboard shortcut, put a
<Kbd>in the row'strailingslot. A separate Shortcut part would do exactly the same thing under another name. MenuSeparator— Use the ordinary<Separator>between groups of rows. Inside a menu panel it gets the right spacing automatically.- An
insetprop — Rows without icons already line up with rows that have them, because the space for the icon or tick is always kept. There is nothing left for an inset prop to fix. modalandopenOnHover— A menu opens when someone presses its trigger, and it always blocks the page behind it until it closes. A submenu row already opens on hover, so neither prop is needed.- An arrow, a backdrop, a scroll viewport and collision settings — A menu needs no arrow pointing at its trigger and no dimmed backdrop. A long menu scrolls inside the panel on its own, and the panel always moves to stay on screen, so there are no settings to tune.