Skip to content

Menu

A button-triggered list of actions, with groups, submenus and filtering.

hero.tsx

Usage guidelines

  • Use Menu for a list of commands that a button opens. Use ContextMenu for the same actions on right-click, and Select or Combobox when the user picks a value for a form or a filter.
  • Open the menu with a MenuTrigger under its Menu. An icon-only trigger needs its own aria-label; a tooltip on it is not its name. Add the target to the name, such as "More actions for Customer support bot", when a list repeats the same trigger.
  • Keep a dialog that a menu item opens as a sibling of the Menu, not inside MenuContent. The item opens it through the dialog's handle: open(null) when the dialog already knows its target, openWithPayload when the item supplies it. Do not keep an open flag in state for this.
  • Use variant="destructive" for an item that deletes or removes, and set it apart with a MenuSeparator.
  • Use MenuCheckboxItem and MenuRadioGroup for view settings that apply as soon as they change, such as sorting a list. Keep the selection visible with the item indicators.
  • Wrap a long action list in MenuFilterProvider and give the MenuInput a name. Put the items in MenuList, and place the separator between groups at the start of the later MenuGroup so it hides with the groups that filtering removes.

Anatomy

tsx
tsx

A filterable menu wraps the root in MenuFilterProvider and fills MenuContent with MenuInputGroup (holding MenuInput and MenuClear), MenuEmpty and MenuList.

MenuContent bundles the portal, positioner and styled popup. Compose MenuPortal, MenuPositioner and MenuPopup only when the positioner needs props that MenuContent does not take.

Examples

Opening a dialog from an item

Each row has its own menu, and one AlertDialog serves the whole list. The Clear logs item calls openWithPayload on the dialog's handle with its app, and the dialog reads the payload of the session.

  • Customer support bot

    Chatflow

  • Release notes writer

    Workflow

  • Contract reviewer

    Workflow

open-dialog.tsx

Checkbox and radio items

Radio items choose one option of a group and checkbox items toggle a setting. Both keep the menu open after a change, and controlling their state preserves the selection when the popup unmounts on close.

checkbox-radio.tsx

MenuSubmenu nests a second MenuContent behind a MenuSubmenuTrigger, which shows the trailing arrow.

submenu.tsx

Filtering a long list

The input takes focus when the menu opens. Typing filters the items and hides groups without a match, and the arrow keys move the highlight while focus stays in the input.

filter.tsx

Keyboard

KeyAction
EnterorSpaceorDown arrowOpens the menu from a focused trigger and focuses the first item.
Up arrowOpens the menu from a focused trigger and focuses the last item.
Down arroworUp arrowMoves focus between items, including disabled ones, and wraps at the ends.
HomeorEndFocuses the first or last item.
Printable charactersFocuses the next item whose label starts with the typed text. In a filterable menu, they type into the input instead.
EnterorSpaceActivates the focused item and closes the menu. Checkbox and radio items toggle and keep the menu open.
EnterorRight arrowOpens the submenu of a focused submenu trigger and focuses its first item.
Left arrowCloses the submenu and returns focus to its trigger.
EscapeCloses the innermost open menu. Closing the top menu returns focus to the trigger.
TabCloses the menu and moves focus to the control after the trigger.

In a right-to-left layout, ArrowLeft opens a submenu and ArrowRight closes it. In a filterable menu, focus stays in the input while ArrowDown and ArrowUp move the highlight, and Enter activates the highlighted item.

API reference

Groups all parts of a dropdown menu supporting items, submenus, checkboxes, radios, and filtering. Doesn't render its own HTML element.

Base UI Menu.Root docs

A menu item that toggles a setting on or off. Renders a <div> element.

Base UI Menu.CheckboxItem docs

Data attributes
AttributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-disabled

Present when the menu checkbox item is disabled.

data-highlighted

Present when the menu checkbox item is highlighted.

Indicates whether the checkbox item is ticked. Renders a <span> element.

Base UI Menu.CheckboxItemIndicator docs

Data attributes
AttributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-disabled

Present when the menu checkbox item is disabled.

data-starting-style

Present when the indicator begins animating in.

data-ending-style

Present when the indicator is animating out.

A button that clears the input text. Requires the menu to be wrapped in Menu.FilterProvider. Renders a <button> element when the input has text.

Base UI Menu.Clear docs

Data attributes
AttributeDescription
data-disabled

Present when the button is disabled.

A styled menu popup bundled with a portal and positioner. Renders a <div> element.

Base UI Menu.Popup docs

Props
PropTypeDefaultDetails
sideOffsetnumber | OffsetFunction4
children requiredReact.ReactNodeNo default
Base UI Menu.Popup docs
Data attributes
AttributeDescription
data-open

Present when the menu is open.

data-closed

Present when the menu is closed.

data-starting-style

Present when the menu begins animating in.

data-ending-style

Present when the menu is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the anchor.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-instant

Values: 'click' | 'dismiss' | 'group' | 'trigger-change'

Present if animations should be instant.

CSS variables
VariableDescription
--available-width

Values: number

The available width between the anchor and the edge of the viewport.

--available-height

Values: number

The available height between the anchor and the edge of the viewport.

--anchor-width

Values: number

The anchor's width.

--anchor-height

Values: number

The anchor's height.

--transform-origin

Values: string

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

Values: number

The width of the menu's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

Values: number

The height of the menu's positioner. It is important to set height to this value when using CSS to animate size changes.

A message shown when the menu has no matching items. Requires the menu to be wrapped in Menu.FilterProvider. Renders a <div> element.

Base UI Menu.Empty docs

Enables filtering for the menu or submenu it wraps. Add Menu.Input to the popup and place its items in Menu.List. Wrap each searchable submenu in its own provider. Doesn't render its own HTML element.

Base UI Menu.FilterProvider docs

Groups related menu items with the corresponding label. Renders a <div> element.

Base UI Menu.Group docs

An accessible label that is automatically associated with its parent group. Renders a <div> element.

Base UI Menu.GroupLabel docs

A search field that filters the menu items. Requires the menu to be wrapped in Menu.FilterProvider. Renders an <input> element.

Base UI Menu.Input docs

Data attributes
AttributeDescription
data-highlighted

Present while the input shows its focus ring. Cleared when keyboard navigation highlights an item.

Wraps MenuInput and MenuClear on an InputGroup surface for filterable menus inside MenuFilterProvider. Renders a <div> element.

Accepts the props of the element it renders.

An individual interactive item in the menu. Renders a <div> element.

Base UI Menu.Item docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
Base UI Menu.Item docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-highlighted

Present when the menu item is highlighted.

data-disabled

Present when the menu item is disabled.

A link in the menu that can be used to navigate to a different page or section. Renders an <a> element.

Base UI Menu.LinkItem docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
closeOnClickbooleantrue
Base UI Menu.LinkItem docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-highlighted

Present when the link is highlighted.

Groups menu items so other content, such as a filter input, can share the popup. Renders a <div> element.

Base UI Menu.List docs

A container for the menu items. Renders a <div> element.

Base UI Menu.Popup docs

Data attributes
AttributeDescription
data-open

Present when the menu is open.

data-closed

Present when the menu is closed.

data-starting-style

Present when the menu begins animating in.

data-ending-style

Present when the menu is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the anchor.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-instant

Values: 'click' | 'dismiss' | 'group' | 'trigger-change'

Present if animations should be instant.

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Base UI Menu.Portal docs

Positions the menu popup against the trigger. Renders a <div> element.

Base UI Menu.Positioner docs

Data attributes
AttributeDescription
data-open

Present when the menu popup is open.

data-closed

Present when the menu popup is closed.

data-anchor-hidden

Present when the anchor is hidden.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the anchor.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to the specified side.

CSS variables
VariableDescription
--available-width

Values: number

The available width between the anchor and the edge of the viewport.

--available-height

Values: number

The available height between the anchor and the edge of the viewport.

--anchor-width

Values: number

The anchor's width.

--anchor-height

Values: number

The anchor's height.

--transform-origin

Values: string

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

Values: number

The width of the menu's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

Values: number

The height of the menu's positioner. It is important to set height to this value when using CSS to animate size changes.

Groups related radio items. Renders a <div> element.

Base UI Menu.RadioGroup docs

Props
PropTypeDefaultDetails
defaultValueValueNo default
onValueChange((value: Value, eventDetails: MenuRadioGroupChangeEventDetails) => void)No default
valueValueNo default
Base UI Menu.RadioGroup docs
Data attributes
AttributeDescription
data-disabled

Whether the component is disabled.

A menu item that works like a radio button in a given group. Renders a <div> element.

Base UI Menu.RadioItem docs

Props
PropTypeDefaultDetails
value requiredValueNo default
Base UI Menu.RadioItem docs
Data attributes
AttributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-disabled

Present when the menu radio item is disabled.

data-highlighted

Present when the menu radio item is highlighted.

Indicates whether the radio item is selected. Renders a <span> element.

Base UI Menu.RadioItemIndicator docs

Data attributes
AttributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-disabled

Present when the menu radio item is disabled.

data-starting-style

Present when the radio indicator begins animating in.

data-ending-style

Present when the radio indicator is animating out.

A separator element accessible to screen readers. Renders a <div> element.

Base UI Separator docs

Data attributes
AttributeDescription
data-orientation

Values: 'horizontal' | 'vertical'

Indicates the orientation of the separator.

Groups all parts of a submenu. Doesn't render its own HTML element.

Base UI Menu.SubmenuRoot docs

A menu item that opens a submenu. Renders a <div> element.

Base UI Menu.SubmenuTrigger docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
Base UI Menu.SubmenuTrigger docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-popup-open

Present when the corresponding submenu is open.

data-highlighted

Present when the submenu trigger is highlighted.

data-disabled

Present when the submenu trigger is disabled.

A button that opens the menu. Renders a <button> element.

Base UI Menu.Trigger docs

Data attributes
AttributeDescription
data-popup-open

Present when the corresponding menu is open.

data-pressed

Present when the trigger is pressed.

data-disabled

Present when the trigger is disabled.

createMenuHandle

Creates a new handle to connect a Menu.Root with detached Menu.Trigger components.

Returns

BaseMenu.Handle<Payload>
Return properties
MemberTypeDescription
open required(triggerId: string) => void

Opens the menu and associates it with the trigger with the given id.

This method should only be called in an event handler or an effect (not during rendering).

close required() => void

Closes the menu.

This method should only be called in an event handler or an effect (not during rendering).

isOpen requiredboolean

Whether the menu is currently open. Returns false while no root is attached to the handle.

useMenuFilter

Parameters
ParameterTypeDescription
optionsGetFilterParametersNo description

Returns

Filter
Return properties
MemberTypeDescription
contains required<Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean

Returns whether the item matches the query anywhere.

startsWith required<Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean

Returns whether the item starts with the query.

endsWith required<Item>(item: Item, query: string, itemToString?: (item: Item) => string) => boolean

Returns whether the item ends with the query.