Blocks Design System

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.

tsx
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
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>
  )
}
Item actions

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.

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
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>
  )
}
Export links

Keyboard

KeyAction
Enter / Space / ArrowDownOn the trigger, opens the menu.
ArrowDown / ArrowUpMoves between items.
Enter / SpaceRuns, checks or chooses the focused item.
EscapeCloses the menu and returns focus to the trigger.
TypingJumps to the item whose label starts with the typed text.

Props

Menu props
PropTypeDefaultDescription
actionsRefRefObject<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.
childrenReactNode | 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.
closeParentOnEscbooleanfalseWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.
defaultOpenbooleanfalseWhether the menu is initially open. To render a controlled menu, use the `open` prop instead.
defaultTriggerIdstring | 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.
disabledbooleanfalseWhether the component should ignore user interaction.
handleMenuHandle<unknown>—A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state.
loopFocusbooleantrueWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
modalbooleantrueDetermines 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.
openboolean—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.
triggerIdstring | 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).
MenuTrigger props
PropTypeDefaultDescription
closeDelaynumber0How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
delaynumber100How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
disabledbooleanfalseWhether the component should ignore user interaction.
handleMenuHandle<unknown>—A handle to associate the trigger with a menu.
nativeButtonbooleantrueWhether 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>`).
openOnHoverboolean—Whether the menu should also open when the trigger is hovered.
payloadunknown—A payload to pass to the menu when it is opened.
renderReactElement<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.

MenuContent props
PropTypeDefaultDescription
align"center" | "start" | "end"'center'How to align the popup relative to the specified side. Submenus and menubars default to `'start'`.
containerPortalContainer—Where the popup mounts. Defaults to `document.body`; pass an element inside a `data-ds-theme` subtree so the popup inherits its theme.
finalFocusboolean | 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.
idstring—@ignore
renderReactElement<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'`.
sideOffsetnumber | OffsetFunction0Distance 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.

MenuItem props
PropTypeDefaultDescription
closeOnClickbooleantrueWhether to close the menu when the item is clicked.
disabledbooleanfalseWhether the component should ignore user interaction.
idstring—@ignore
labelstring—Overrides the text label to use when the item is matched during keyboard text navigation.
nativeButtonbooleantrueWhether 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.
renderReactElement<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.

MenuLinkItem props
PropTypeDefaultDescription
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
idstring—@ignore
labelstring—Overrides the text label to use when the item is matched during keyboard text navigation.
renderReactElement<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.

MenuSeparator props
PropTypeDefaultDescription
orientation"horizontal" | "vertical"'horizontal'The orientation of the separator.
renderReactElement<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.

MenuGroup props
PropTypeDefaultDescription
childrenReactNode—The content of the component.
renderReactElement<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.

MenuGroupLabel props
PropTypeDefaultDescription
renderReactElement<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.

MenuCheckboxItem props
PropTypeDefaultDescription
checkedboolean—Whether the checkbox item is currently ticked. To render an uncontrolled checkbox item, use the `defaultChecked` prop instead.
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
defaultCheckedbooleanfalseWhether the checkbox item is initially ticked. To render a controlled checkbox item, use the `checked` prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
idstring—@ignore
labelstring—Overrides the text label to use when the item is matched during keyboard text navigation.
nativeButtonbooleantrueWhether 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.
renderReactElement<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.

MenuRadioGroup props
PropTypeDefaultDescription
childrenReactNode—The content of the component.
defaultValueany—The uncontrolled value of the radio item that should be initially selected. To render a controlled radio group, use the `value` prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
onValueChange((value: any, eventDetails: MenuRootChangeEventDetails) => void)—Function called when the selected value changes.
renderReactElement<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.
valueany—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.

MenuRadioItem props
PropTypeDefaultDescription
value (required)any—Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected.
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
disabledbooleanfalseWhether the component should ignore user interaction.
idstring—@ignore
labelstring—Overrides the text label to use when the item is matched during keyboard text navigation.
nativeButtonbooleantrueWhether 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.
renderReactElement<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.