Menu
A list of actions in a dropdown, enhanced with keyboard navigation.
API reference
Import the component and place its parts the following way:
import { Menu } from '@base-ui-components/react/menu';
<Menu.Root>
<Menu.Trigger />
<Menu.Portal>
<Menu.Backdrop />
<Menu.Positioner>
<Menu.Popup>
<Menu.Arrow />
<Menu.Item />
<Menu.Separator />
<Menu.Group>
<Menu.GroupLabel />
</Menu.Group>
<Menu.RadioGroup>
<Menu.RadioItem />
</Menu.RadioGroup>
<Menu.CheckboxItem />
{/* Submenu */}
<Menu.Root>
<Menu.SubmenuTrigger />
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>...</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
Root
Groups all parts of the menu. Doesn’t render its own HTML element.
Prop | Type | Default | |
---|---|---|---|
closeParentOnEsc | boolean | true | |
defaultOpen | boolean | false | |
delay | number | 100 | |
disabled | boolean | false | |
loop | boolean | true | |
onOpenChange | (open, event) => void | undefined | |
open | boolean | undefined | |
openOnHover | boolean | undefined | |
orientation | 'horizontal' | 'vertical' | 'vertical' |
Trigger
A button that opens the menu.
Renders a <button>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
disabled | boolean | false | |
label | string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-popup-open | Present when the corresponding menu is open. | |
data-pressed | Present when the trigger is pressed. |
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>
.
Prop | Type | Default | |
---|---|---|---|
container | React.Ref | HTMLElement | null | undefined | |
keepMounted | boolean | false |
Positioner
Positions the menu popup against the trigger.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
align | 'start' | 'center' | 'end' | undefined | |
alignOffset | number | 0 | |
anchor | | React.Ref | undefined | |
arrowPadding | number | 5 | |
className | string | (state) => string | undefined | |
collisionBoundary | | 'clippingAncestors' | 'clipping-ancestors' | |
collisionPadding | number | Rect | 5 | |
keepMounted | boolean | false | |
positionMethod | 'absolute' | 'fixed' | 'absolute' | |
render | | React.ReactElement | undefined | |
side | | 'bottom' | undefined | |
sideOffset | number | 0 | |
sticky | boolean | false |
Attribute | Description | |
---|---|---|
data-anchor-hidden | Present when the anchor is hidden. | |
data-open | Present when the menu popup is open. | |
data-side | Indicates which side the menu is positioned relative to the trigger. | |
data-unchecked | Present when the menu popup is closed. |
CSS Variable | Description | |
---|---|---|
--anchor-height | The anchor's height. | |
--anchor-width | The anchor's width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. |
Popup
A container for the menu items.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-closed | Present when the menu is closed. | |
data-ending-style | Present when the menu is animating out. | |
data-open | Present when the menu is open. | |
data-side | Indicates which side the menu is positioned relative to the trigger. | |
data-starting-style | Present when the menu is animating in. |
Arrow
Displays an element positioned against the menu anchor.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-anchor-hidden | Present when the anchor is hidden. | |
data-open | Present when the menu popup is open. | |
data-side | Indicates which side the menu is positioned relative to the trigger. | |
data-uncentered | Present when the tooltip arrow is uncentered. | |
data-unchecked | Present when the menu popup is closed. |
Item
An individual interactive item in the menu.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
closeOnClick | boolean | true | |
disabled | boolean | false | |
label | string | undefined | |
onClick | (event) => void | undefined |
Group
Groups related menu items with the corresponding label.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
children | React.ReactNode | undefined | |
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |
RadioGroup
Groups related radio items.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
children | React.ReactNode | undefined | |
className | string | (state) => string | undefined | |
defaultValue | any | undefined | |
onValueChange | (value, event) => void | () => {} | |
render | | React.ReactElement | undefined | |
value | any | undefined |
RadioItem
A menu item that works like a radio button in a given group.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
closeOnClick | boolean | true | |
disabled | boolean | false | |
label | string | undefined | |
onClick | (event) => void | undefined | |
value | any | undefined |
Attribute | Description | |
---|---|---|
data-checked | Present when the menu radio item is selected. | |
data-unchecked | Present when the menu radio item is not selected. |
RadioItemIndicator
Indicates whether the radio item is selected.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
keepMounted | boolean | true | |
render | | React.ReactElement | undefined |
CheckboxItem
A menu item that toggles a setting on or off.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
checked | boolean | undefined | |
closeOnClick | boolean | true | |
defaultChecked | boolean | false | |
disabled | boolean | false | |
label | string | undefined | |
onCheckedChange | (checked, event) => void | undefined | |
onClick | (event) => void | undefined |
CheckboxItemIndicator
Indicates whether the checkbox item is ticked.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
keepMounted | boolean | true | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-checked | Present when the menu checkbox item is checked. | |
data-unchecked | Present when the menu checkbox item is not checked. |
SubmenuTrigger
A menu item that opens a submenu.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
disabled | boolean | false | |
label | string | undefined | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-popup-open | Present when the corresponding submenu is open. |
Separator
A separator element accessible to screen readers.
Renders a <div>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
render | | React.ReactElement | undefined |