Menu
A list of actions and settings that opens from a button.
Items can carry a shortcut hint, toggle a setting, pick one of a group, or open a submenu.
variant="destructive" marks an action that can’t be undone. The arrow keys move through the
list, and typing jumps to an item.
Dependencies
What it's built from and what's built from it in Base, read from the imports in its source.
| Uses | KbdScroll AreaprimitiveTextprimitive |
|---|---|
| Used by | Menubar |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20lucide-react@1.73.0 |
Installation
Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Menu
A list of actions and options, opened from a button or a right-click. Put its trigger and content inside.
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- controller
Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with
createMenuController().Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultOpen
Whether the menu starts open, when uncontrolled.
Type boolean · Default false
- delay
Milliseconds the pointer rests on a submenu trigger before its submenu opens.
Type number · Default 100
- dismissible
Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass
falsewhile it holds unsaved work, and ask inonDismissAttempt.Type boolean · Default true
- items
The menu as data. Renders the content for you, unless you place a content part of your own, and runs the items' shortcuts.
Type MenuData
- itemShortcuts
Whether a data menu runs its items' shortcuts while closed.
Type boolean · Default true
- loop
Whether arrow keys wrap from the last item to the first.
Type boolean · Default true
- modal
"pointer": an outside press only closes the menu.true: also locks scroll, traps focus and makes the rest of the page inert.false: outside presses reach what they hit.Type boolean | "pointer" · Default "pointer", or true while it presents as a sheet
- onAction
Runs for every plain item, including items in submenus, with the item's value. Return a Promise to mark the item pending until it settles: it gets
data-pending,aria-busyandaria-disabled, the menu stays open, and choosing it again waits. It closes once the Promise resolves, and a rejection keeps it open with the reason in the item'serrorstate until the next try.Type (value: string, details: MenuActionDetails) => unknown
- onCheckedChange
Runs when any checkbox item in the menu or its submenus toggles, with the item's value in
details.value. Made for data menus.Type (checked: boolean, details: MenuCheckedChangeDetails) => void
- onDismissAttempt
Runs when
dismissiblerefused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.Type (details: { reason: "outside-press"; event?: MouseEvent; } | { reason: "escape-key"; event?: KeyboardEvent; } | { reason: "back"; event?: Event; } | { reason: "swipe"; event?: PointerEvent | TouchEvent; }) => void
- onOpenChange
Runs when the menu wants to open or close.
details.reasonsays why, anddetails.cancel()stops it.Type (open: boolean, details: ChangeDetails<MenuOpenChangeReason>) => void
- onOpenChangeComplete
Runs once the menu has finished opening or closing, after any animation.
Type (open: boolean) => void
- onPayloadChange
Runs when the payload the content shows changes: a trigger or context area with another payload opens the menu, or takes the open menu over, which fires no
onOpenChange, and so does a controller'sopen({ payload })on the open menu.details.cancel()keeps the previous payload.Type (payload: unknown, details: ChangeDetails<MenuPayloadChangeReason>) => void
- onValueChange
Runs when any radio group in the menu or its submenus changes, with the group in
details.group. Made for data menus.Type (value: string, details: MenuValueChangeDetails) => void
- open
Whether the menu is open. Pass it to control the menu.
Type boolean
- pendingAnnouncement
What screen readers hear once an item has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
Type string · Default "Loading"
- presentation
How the menu presents.
"sheet"slides it up from the bottom of the screen, where it can be swiped away and submenus open in its place, and"auto"does that on small touch screens. Decided each time it opens; the server renders"popover"for"auto". A context menu and a menu in a menubar are always popovers.Type PresentationSetting<"popover"> · Default "popover"
MenuCheckboxItem
An item that turns a setting on and off, with its check mark built in.
- checked
Whether the item is checked. Pass it to control the item.
Type boolean
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuCheckboxItemState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuCheckboxItemState) => string)
- closeOnSelect
Whether toggling closes the menu.
Type boolean · Default false
- defaultChecked
Whether the item starts checked, when uncontrolled.
Type boolean · Default false
- disabled
Keeps the item focusable but stops it from toggling, as the menu pattern asks.
Type boolean
- label
The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that.Type string
- onCheckedChange
Runs when the item wants to toggle.
details.reasonsays why, anddetails.cancel()stops it.Type (checked: boolean, details: ChangeDetails<MenuCheckedChangeReason>) => void
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuCheckboxItemState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuCheckboxItemState) => CSSProperties)
- value*
Identifies the item, in the menu's
onCheckedChange.Type string
MenuContent
The menu's popup. Placed below its trigger with a 4px gap unless you set side and sideOffset.
- align
How the popup lines up with the anchor along that side.
startandendfollow the reading direction. How the menu lines up with the trigger along that side.Type "center" | "start" | "end" · Default "start"
- alignOffset
Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.
Type number
- anchor
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like
{ x, y }, or anything withgetBoundingClientRect(). It's read on every check, so it can move. A controller'sopen({ anchor })wins for that open.Type string | Anchor | null
- arrowPadding
Space to keep between the arrow and the popup's corners, in pixels.
Type number · Default 6
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuContentState<unknown>) => string)
- collisionPadding
Space to keep from the viewport edges, in pixels.
Type number · Default 8
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- finalFocus
Where focus goes when the menu closes while focus is inside it.
"trigger"returns it to the trigger and"none"leaves it. A CSS selector, an element or a function picks a specific element.Type PopupFocusTarget · Default "trigger"
- keepMounted
Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuContentState<unknown>>
- side
Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the menu opens on. Submenus open to the side, mirrored in right-to-left layouts.
Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "bottom"
- sideOffset
Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels.
Type number · Default 4
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuContentState<unknown>) => CSSProperties)
MenuGroup
A group of items, named by its MenuGroupLabel.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
MenuGroupLabel
Names a group of items.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
MenuItem
An action. Its shortcut shows as a hint at the end of the row.
- variantours
destructivemarks an action that deletes or can't be undone.Type "default" | "destructive" · Default default
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuItemState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuItemState) => string)
- closeOnSelect
Whether running the item closes the menu.
Type boolean · Default true
- destructive
Styles the item as dangerous, like Delete. Sets
data-destructive.Type boolean
- disabled
Keeps the item focusable but stops it from running, as the menu pattern asks. Sets
data-disabledandaria-disabled.Type boolean
- label
The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that.Type string
- onSelect
Runs when the item is selected, by pointer or keyboard, with the event that selected it, or a new
selectEvent when no DOM event did. Callevent.preventDefault()to keep the menu open and skiponAction. Return a Promise to mark the item pending until it settles, likeonAction.Type (event: Event) => unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuItemState>
- shortcut
A keyboard shortcut like
"mod+n". Shows⌘Non Apple platforms andCtrl+Nelsewhere, and setsaria-keyshortcuts.Type string
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuItemState) => CSSProperties)
- value
Passed to
onActionwhen the item runs.Type string
MenuRadioGroup
Radio items that share one value. T is inferred from value, defaultValue or onValueChange.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuRadioGroupState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuRadioGroupState) => string)
- defaultValue
The value selected at first, when uncontrolled.
Type string | null
- name
Identifies the group in the menu's
onValueChange. Defaults to a generated id, and the group then keeps its choice by its place among the menu's groups. Give a group that's shown only some of the time a name, so it keeps its own.Type string
- onValueChange
Runs when the selection wants to change.
details.reasonsays why, anddetails.cancel()stops it.Type (value: T, details: ChangeDetails<MenuValueChangeReason>) => void
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuRadioGroupState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuRadioGroupState) => CSSProperties)
- value
The selected value. Pass it to control the group.
nullselects nothing.Type string | null
MenuRadioItem
One choice in a MenuRadioGroup, with its dot built in.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuRadioItemState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuRadioItemState) => string)
- closeOnSelect
Whether choosing the item closes the menu.
Type boolean · Default false
- disabled
Keeps the item focusable but stops it from being chosen, as the menu pattern asks.
Type boolean
- label
The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that.Type string
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuRadioItemState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuRadioItemState) => CSSProperties)
- value*
Selected in the group when the item is chosen.
Type string
MenuSeparator
A line between groups of items.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
MenuShortcut
A keyboard hint at the end of an item, when you render one yourself.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
MenuSub
A submenu. Put its MenuSubTrigger and MenuSubContent inside, in a menu's content.
- controller
Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with
createMenuController().Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultOpen
Whether the menu starts open, when uncontrolled.
Type boolean · Default false
- delay
Milliseconds the pointer rests on a submenu trigger before its submenu opens.
Type number · Default 100
- loop
Whether arrow keys wrap from the last item to the first.
Type boolean · Default true
- onOpenChange
Runs when the menu wants to open or close.
details.reasonsays why, anddetails.cancel()stops it.Type (open: boolean, details: ChangeDetails<MenuOpenChangeReason>) => void
- onOpenChangeComplete
Runs once the menu has finished opening or closing, after any animation.
Type (open: boolean) => void
- open
Whether the menu is open. Pass it to control the menu.
Type boolean
MenuSubContent
A submenu's popup.
- align
How the popup lines up with the anchor along that side.
startandendfollow the reading direction. How the menu lines up with the trigger along that side.Type "center" | "start" | "end" · Default "start"
- alignOffset
Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.
Type number
- anchor
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like
{ x, y }, or anything withgetBoundingClientRect(). It's read on every check, so it can move. A controller'sopen({ anchor })wins for that open.Type string | Anchor | null
- arrowPadding
Space to keep between the arrow and the popup's corners, in pixels.
Type number · Default 6
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuContentState<unknown>) => string)
- collisionPadding
Space to keep from the viewport edges, in pixels.
Type number · Default 8
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- finalFocus
Where focus goes when the menu closes while focus is inside it.
"trigger"returns it to the trigger and"none"leaves it. A CSS selector, an element or a function picks a specific element.Type PopupFocusTarget · Default "trigger"
- keepMounted
Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuContentState<unknown>>
- side
Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the menu opens on. Submenus open to the side, mirrored in right-to-left layouts.
Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "bottom"
- sideOffset
Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels.
Type number · Default 4
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuContentState<unknown>) => CSSProperties)
MenuSubTrigger
Opens a submenu, with its chevron built in.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuTriggerState) => string)
- disabled
Keeps the submenu trigger focusable but stops it from opening its submenu, as the menu pattern asks. Sets
data-disabledandaria-disabled.Type boolean
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuTriggerState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuTriggerState) => CSSProperties)
MenuTrigger
The button that opens the menu. A trigger outside the menu connects through controller.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: MenuTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: MenuTriggerState) => string)
- controller
Connects a trigger outside the menu, like one per table row, to the menu with this controller.
Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>
- disabled
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless
focusableWhenDisabledis set.Type boolean · Default false
- focusableWhenDisabled
Keeps a disabled trigger in the tab order with
aria-disabledinstead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.Type boolean · Default false
- payload
Data for the content to render when this trigger opens the menu, like the row it belongs to.
Type unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<MenuTriggerState>
- shortcut
A keyboard shortcut that opens the menu from anywhere, like
"mod+j".modis Command on Apple platforms and Control elsewhere. Setsaria-keyshortcuts.Type string
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: MenuTriggerState) => CSSProperties)