Menu
A menu of actions and options opened from a trigger, on Base UI Menu: arrow keys move between items, typing jumps to an item, and Escape closes it and returns focus to the trigger. Use it for commands; use Select to choose a value in a form, and links for navigation that should be visible.
import { Menu, MenuContent, MenuItem, MenuTrigger } from '@blocks/design-system'From a Server Component, import the parts by name. Client-authored code can use Menu.Trigger, Menu.Content, Menu.Item and the rest.
Actions and options
MenuItem runs its onClick and closes the menu. MenuRadioGroup with MenuRadioItems holds one choice, and MenuCheckboxItem toggles; both show and announce their state. Group items under a MenuGroupLabel and divide groups with MenuSeparator.
Sorted by newest · showing done items · 0 copies
Source · menu/item-actions.tsx
'use client'
import { Body, Button, Menu, Stack } from '@blocks/design-system'
import { useState } from 'react'
export default function ItemActions() {
const [sort, setSort] = useState('newest')
const [showDone, setShowDone] = useState(true)
const [copies, setCopies] = useState(0)
return (
<Stack gap="sm" align="start">
<Menu>
<Menu.Trigger render={<Button type="button" />}>Item actions</Menu.Trigger>
<Menu.Content>
<Menu.Item onClick={() => setCopies((count) => count + 1)}>Duplicate</Menu.Item>
<Menu.Item disabled>Move to another board</Menu.Item>
<Menu.LinkItem href="#item-page">Open item page</Menu.LinkItem>
<Menu.Separator />
<Menu.Group>
<Menu.GroupLabel>Sort by</Menu.GroupLabel>
<Menu.RadioGroup value={sort} onValueChange={(value) => setSort(String(value))}>
<Menu.RadioItem value="newest">Newest</Menu.RadioItem>
<Menu.RadioItem value="oldest">Oldest</Menu.RadioItem>
<Menu.RadioItem value="name">Name</Menu.RadioItem>
</Menu.RadioGroup>
</Menu.Group>
<Menu.Separator />
<Menu.CheckboxItem checked={showDone} onCheckedChange={setShowDone}>
Show done items
</Menu.CheckboxItem>
</Menu.Content>
</Menu>
<Body margin="none" role="status" aria-label="Board view">
Sorted by {sort} · {showDone ? 'showing' : 'hiding'} done items · {copies} {copies === 1 ? 'copy' : 'copies'}
</Body>
</Stack>
)
}A disabled item stays in the menu and can be reached with the arrow keys, so people learn it exists, but it can’t be activated. Base UI follows the WAI-ARIA menu pattern here; it has no option to skip disabled items.
Links
MenuLinkItem is a real link styled as an item. A menu of links needs no handlers, so it can live in a Server Component.
Source · menu/named-parts.tsx
// A Server Component: named parts with link items only (no handlers needed).
import { Button, Menu, MenuContent, MenuGroup, MenuGroupLabel, MenuLinkItem, MenuSeparator, MenuTrigger } from '@blocks/design-system'
export default function NamedParts() {
return (
<Menu>
<MenuTrigger render={<Button type="button" variant="ghost" />}>Export</MenuTrigger>
<MenuContent>
<MenuGroup>
<MenuGroupLabel>This station</MenuGroupLabel>
<MenuLinkItem href="#export-csv">Readings as CSV</MenuLinkItem>
<MenuLinkItem href="#export-json">Readings as JSON</MenuLinkItem>
</MenuGroup>
<MenuSeparator />
<MenuLinkItem href="#export-all">All stations…</MenuLinkItem>
</MenuContent>
</Menu>
)
}Keyboard
| Key | Action |
|---|---|
| Enter / Space / ArrowDown | On the trigger, opens the menu. |
| ArrowDown / ArrowUp | Moves between items. |
| Enter / Space | Runs, checks or chooses the focused item. |
| Escape | Closes the menu and returns focus to the trigger. |
| Typing | Jumps to the item whose label starts with the typed text. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
actionsRef | RefObject<MenuRootActions | null> | — | A ref to imperative actions. - `unmount`: Manually unmounts the menu. Call this after any externally controlled closing animation finishes. - `close`: When specified, the menu can be closed imperatively. |
children | ReactNode | PayloadChildRenderFunction<unknown> | — | The content of the menu. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
closeParentOnEsc | boolean | false | When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu. |
defaultOpen | boolean | false | Whether the menu is initially open. To render a controlled menu, use the `open` prop instead. |
defaultTriggerId | string | null | — | ID of the trigger that the menu is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open menu. |
disabled | boolean | false | Whether the component should ignore user interaction. |
handle | MenuHandle<unknown> | — | A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state. |
highlightItemOnHover | boolean | true | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. |
loopFocus | boolean | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. |
modal | boolean | true | Determines if the menu enters a modal state when open. - `true`: user interaction is limited to the menu: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. Nested menus ignore this prop, and menus opened by hover are never modal. |
onOpenChange | ((open: boolean, eventDetails: MenuRootChangeEventDetails) => void) | — | Event handler called when the menu is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | — | Event handler called after any animations complete when the menu is opened or closed. |
open | boolean | — | Whether the menu is currently open. |
orientation | "horizontal" | "vertical" | 'vertical' | The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys. |
triggerId | string | null | — | ID of the trigger that the menu is associated with. This is useful in conjunction with the `open` prop to create a controlled menu. There's no need to specify this prop when the menu is uncontrolled (that is, when the `open` prop is not set). |
| Prop | Type | Default | Description |
|---|---|---|---|
closeDelay | number | 0 | How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
delay | number | 100 | How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
disabled | boolean | false | Whether the component should ignore user interaction. |
handle | MenuHandle<unknown> | — | A handle to associate the trigger with a menu. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
openOnHover | boolean | — | Whether the menu should also open when the trigger is hovered. |
payload | unknown | — | A payload to pass to the menu when it is opened. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuTriggerState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
align | "center" | "start" | "end" | 'center' | How to align the popup relative to the specified side. Submenus and menubars default to `'start'`. |
container | PortalContainer | — | Where the popup mounts. Defaults to `document.body`; pass an element inside a `data-ds-theme` subtree so the popup inherits its theme. |
finalFocus | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) | — | Determines the element to focus when the menu is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
id | string | — | @ignore |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuPopupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
side | "top" | "bottom" | "left" | "right" | "inline-end" | "inline-start" | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. Submenus and vertical menubars default to `'inline-end'`. |
sideOffset | number | OffsetFunction | 0 | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. @example ```jsx <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} /> ``` |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
closeOnClick | boolean | true | Whether to close the menu when the item is clicked. |
disabled | boolean | false | Whether the component should ignore user interaction. |
id | string | — | @ignore |
label | string | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
onClick | ((event: BaseUIEvent<MouseEvent<HTMLDivElement, MouseEvent>>) => void) | — | The click handler for the menu item. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuItemState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
closeOnClick | boolean | false | Whether to close the menu when the item is clicked. |
id | string | — | @ignore |
label | string | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, MenuLinkItemState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | 'horizontal' | The orientation of the separator. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SeparatorState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The content of the component. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuGroupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuGroupLabelState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Whether the checkbox item is currently ticked. To render an uncontrolled checkbox item, use the `defaultChecked` prop instead. |
closeOnClick | boolean | false | Whether to close the menu when the item is clicked. |
defaultChecked | boolean | false | Whether the checkbox item is initially ticked. To render a controlled checkbox item, use the `checked` prop instead. |
disabled | boolean | false | Whether the component should ignore user interaction. |
id | string | — | @ignore |
label | string | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
onCheckedChange | ((checked: boolean, eventDetails: MenuRootChangeEventDetails) => void) | — | Event handler called when the checkbox item is ticked or unticked. |
onClick | ((event: BaseUIEvent<MouseEvent<HTMLDivElement, MouseEvent>>) => void) | — | The click handler for the menu item. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuCheckboxItemState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The content of the component. |
defaultValue | any | — | The uncontrolled value of the radio item that should be initially selected. To render a controlled radio group, use the `value` prop instead. |
disabled | boolean | false | Whether the component should ignore user interaction. |
onValueChange | ((value: any, eventDetails: MenuRootChangeEventDetails) => void) | — | Function called when the selected value changes. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuRadioGroupState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
value | any | — | The controlled value of the radio item that should be currently selected. To render an uncontrolled radio group, use the `defaultValue` prop instead. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
value (required) | any | — | Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected. |
closeOnClick | boolean | false | Whether to close the menu when the item is clicked. |
disabled | boolean | false | Whether the component should ignore user interaction. |
id | string | — | @ignore |
label | string | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
onClick | ((event: BaseUIEvent<MouseEvent<HTMLDivElement, MouseEvent>>) => void) | — | The click handler for the menu item. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuRadioItemState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
Accessibility
- Name the trigger by what the menu holds (“Item actions”, “Export”).
- Show the result of an option outside the menu as well, since the menu closes.
- Keep destructive actions out of menus or confirm them in a Modal.