Menubar
A horizontal row of menus, like the menu bar of a desktop application.
<Menubar>
<MenubarMenu>
<MenubarTrigger>Report</MenubarTrigger>
<MenubarContent>
<MenubarItem>
New report <MenubarShortcut>⌘N</MenubarShortcut>
</MenubarItem>
<MenubarItem>
Duplicate <MenubarShortcut>⌘D</MenubarShortcut>
</MenubarItem>
<MenubarSeparator />
<MenubarItem>
Export PDF <MenubarShortcut>⌘E</MenubarShortcut>
</MenubarItem>
<MenubarItem>Schedule delivery</MenubarItem>
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Edit</MenubarTrigger>
<MenubarContent>
<MenubarItem>
Undo <MenubarShortcut>⌘Z</MenubarShortcut>
</MenubarItem>
<MenubarItem>
Redo <MenubarShortcut>⇧⌘Z</MenubarShortcut>
</MenubarItem>
<MenubarSeparator />
<MenubarItem>Add section</MenubarItem>
<MenubarItem variant="destructive">Delete section</MenubarItem>
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Data</MenubarTrigger>
<MenubarContent>
<MenubarItem>Refresh</MenubarItem>
<MenubarItem disabled>Edit query</MenubarItem>
</MenubarContent>
</MenubarMenu>
</Menubar>Usage
import {
Menubar,
MenubarContent,
MenubarItem,
MenubarMenu,
MenubarTrigger,
} from "@zenoxai/ui/components/menubar"
<Menubar>
<MenubarMenu>
<MenubarTrigger>Report</MenubarTrigger>
<MenubarContent>
<MenubarItem onClick={createReport}>New report</MenubarItem>
<MenubarItem onClick={exportPdf}>Export PDF</MenubarItem>
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Edit</MenubarTrigger>
<MenubarContent>{/* items */}</MenubarContent>
</MenubarMenu>
</Menubar>
Use a menubar at the top of a document-like workspace, such as a report or dashboard editor, where the commands are many and fall into a few stable categories. Once one menu is open, moving the pointer or pressing the left and right arrow keys opens its neighbors.
- For the actions of a single object (a row, a card), use a Dropdown Menu.
- For a shortcut on right-click, use a Context Menu.
- For page navigation, use links in the sidebar or the page header, not a menubar.
Each MenubarMenu is a Dropdown Menu with its own trigger, and
takes the same parts: items with shortcuts, a destructive variant, checkbox and radio items,
labels, separators and submenus.
Examples
Checkbox and radio items
A “View” menu holds display settings. Checkbox and radio items keep the menu open when toggled.
The check sits at the right edge, as in Dropdown Menu and Context Menu, so their text lines up
with labels and plain items without inset.
function MenubarWithOptions() {
const [showFilters, setShowFilters] = React.useState(true)
const [showSummary, setShowSummary] = React.useState(false)
const [density, setDensity] = React.useState("compact")
return (
<Menubar>
<MenubarMenu>
<MenubarTrigger>View</MenubarTrigger>
<MenubarContent className="w-52">
<MenubarCheckboxItem
checked={showFilters}
onCheckedChange={setShowFilters}
>
Filter bar
</MenubarCheckboxItem>
<MenubarCheckboxItem
checked={showSummary}
onCheckedChange={setShowSummary}
>
Summary tiles
</MenubarCheckboxItem>
<MenubarSeparator />
<MenubarLabel>Density</MenubarLabel>
<MenubarRadioGroup value={density} onValueChange={setDensity}>
<MenubarRadioItem value="compact">Compact</MenubarRadioItem>
<MenubarRadioItem value="comfortable">Comfortable</MenubarRadioItem>
</MenubarRadioGroup>
</MenubarContent>
</MenubarMenu>
</Menubar>
)
}Submenu
<Menubar>
<MenubarMenu>
<MenubarTrigger>Share</MenubarTrigger>
<MenubarContent className="w-48">
<MenubarItem>Copy link</MenubarItem>
<MenubarSub>
<MenubarSubTrigger>Send to</MenubarSubTrigger>
<MenubarSubContent>
<MenubarItem>Email</MenubarItem>
<MenubarItem>Slack channel</MenubarItem>
<MenubarItem>Ticketing system</MenubarItem>
</MenubarSubContent>
</MenubarSub>
<MenubarSeparator />
<MenubarItem>Manage access</MenubarItem>
</MenubarContent>
</MenubarMenu>
</Menubar>Accessibility
- The bar has
role="menubar". Tab moves focus to the bar as a single stop; left and right arrow keys move between triggers, down arrow or Enter opens a menu, and Escape closes it. MenubarShortcutonly displays the shortcut. Bind the key yourself.
API reference
Generated from the TypeScript source. className, style and children are accepted everywhere and omitted below.
Menubar
Menubar is a horizontal bar of menus, like the File and Edit menus of a desktop app, with arrow keys moving between them. Each MenubarMenu holds a MenubarTrigger and its MenubarContent. For a single menu, use DropdownMenu; for site navigation, NavigationMenu.
| Prop | Type | Default |
|---|---|---|
disabled | booleanWhether the whole menubar is disabled. | false |
loopFocus | booleanWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. | true |
modal | booleanWhether the menubar is modal. | true |
orientation | "horizontal" | "vertical"The orientation of the menubar. | 'horizontal' |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenubarState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
MenubarPortal
MenubarPortal moves a menu to the end of the document body. MenubarContent renders one already.
| Prop | Type | Default |
|---|---|---|
container | HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | nullA parent element to render the portal element into. | - |
keepMounted | booleanWhether to keep the portal mounted in the DOM while the popup is hidden. | false |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuPortalState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
MenubarMenu
MenubarMenu is one menu of the bar: a trigger and its content.
| Prop | Type | Default |
|---|---|---|
actionsRef | RefObject<MenuRootActions | null>A ref to imperative actions. - `unmount`: Ends the closing phase of the menu after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the menu completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the menu imperatively when called. | - |
closeParentOnEsc | booleanWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu. | false |
defaultOpen | booleanWhether the menu is initially open. | false |
defaultTriggerId | string | nullID 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 | booleanWhether the component should ignore user interaction. | false |
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 | booleanWhether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. | true |
loopFocus | booleanWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. | true |
modal | booleanDetermines 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. | true |
onItemHighlighted | ((highlightedItem: HTMLElement, eventDetails: MenuRootHighlightEventDetails) => void)Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item element (or `undefined` if no item is highlighted) and details containing the reason for the change, the event, and the item's text label. The `reason` can be: - `'keyboard'`: the highlight changed due to keyboard navigation. - `'pointer'`: the highlight changed due to pointer hovering. The event may be a `MouseEvent` rather than a `PointerEvent`. - `'none'`: the highlight changed for another reason, such as automatic highlighting while filtering, the item list changing, or the popup opening or closing. | - |
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 | booleanWhether the menu is currently open. | - |
orientation | "horizontal" | "vertical"The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys. | 'vertical' |
triggerId | string | nullID 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). | - |
MenubarTrigger
| Prop | Type | Default |
|---|---|---|
closeDelay | numberHow long to wait before closing the menu that was opened on hover. Specified in milliseconds. | 0 |
delay | numberHow long to wait before the menu may be opened on hover. Specified in milliseconds. | 100 |
disabled | booleanWhether the component should ignore user interaction. | false |
handle | MenuHandle<unknown>A handle to associate the trigger with a menu. | - |
nativeButton | booleanWhether 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>`). | true |
openOnHover | booleanWhether the menu should also open when the trigger is hovered. | - |
payload | unknownA 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. | - |
MenubarContent
| Prop | Type | Default |
|---|---|---|
align | "center" | "start" | "end"How to align the popup relative to the specified side. | start |
alignOffset | number | OffsetFunctionAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. | 0 |
finalFocus | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)Determines the element to focus when the menu is closed. | - |
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. | - |
side | "left" | "right" | "top" | "bottom" | "inline-end" | "inline-start"Which side of the anchor element to align the popup against. May automatically change to avoid collisions. | bottom |
sideOffset | number | OffsetFunctionDistance 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. | 0 |
MenubarGroup
| Prop | Type | Default |
|---|---|---|
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. | - |
MenubarSeparator
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical"The orientation of the separator. | vertical |
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. | - |
MenubarLabel
| Prop | Type | Default |
|---|---|---|
inset | booleanIndents the text to line up with items that have a leading icon. | - |
MenubarItem
| Prop | Type | Default |
|---|---|---|
closeOnClick | booleanWhether to close the menu when the item is clicked. | true |
disabled | booleanWhether the component should ignore user interaction. | false |
id | string@ignore | - |
inset | booleanIndents the text to line up with items that have a leading icon. | - |
label | stringOverrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided. | - |
nativeButton | booleanWhether 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>`). | true |
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. | - |
variant | "default" | "destructive"`destructive` colors the item red, for delete and other risky actions. | default |
MenubarShortcut
MenubarShortcut is the key hint at the right edge of an item. It is display text only: bind the keys yourself.
No props of its own. Accepts the props of the element it renders.
MenubarCheckboxItem
| Prop | Type | Default |
|---|---|---|
checked | booleanWhether the checkbox item is currently ticked. | - |
closeOnClick | booleanWhether to close the menu when the item is clicked. | false |
defaultChecked | booleanWhether the checkbox item is initially ticked. | false |
disabled | booleanWhether the component should ignore user interaction. | false |
id | string@ignore | - |
inset | boolean | - |
label | stringOverrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided. | - |
nativeButton | booleanWhether 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>`). | true |
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. | - |
MenubarRadioGroup
| Prop | Type | Default |
|---|---|---|
defaultValue | anyThe uncontrolled value of the radio item that should be initially selected. | - |
disabled | booleanWhether the component should ignore user interaction. | false |
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. | - |
value | anyThe controlled value of the radio item that should be currently selected. | - |
MenubarRadioItem
| Prop | Type | Default |
|---|---|---|
closeOnClick | booleanWhether to close the menu when the item is clicked. | false |
disabled | booleanWhether the component should ignore user interaction. | false |
id | string@ignore | - |
inset | boolean | - |
label | stringOverrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided. | - |
nativeButton | booleanWhether 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>`). | true |
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. | - |
value* | anyValue of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected. | - |
MenubarSub
| Prop | Type | Default |
|---|---|---|
actionsRef | RefObject<MenuRootActions | null>A ref to imperative actions. - `unmount`: Ends the closing phase of the menu after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the menu completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the menu imperatively when called. | - |
closeParentOnEsc | booleanWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu. | false |
defaultOpen | booleanWhether the menu is initially open. | false |
disabled | booleanWhether the component should ignore user interaction. | false |
highlightItemOnHover | booleanWhether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. | true |
loopFocus | booleanWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. | true |
onItemHighlighted | ((highlightedItem: HTMLElement, eventDetails: MenuRootHighlightEventDetails) => void)Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item element (or `undefined` if no item is highlighted) and details containing the reason for the change, the event, and the item's text label. The `reason` can be: - `'keyboard'`: the highlight changed due to keyboard navigation. - `'pointer'`: the highlight changed due to pointer hovering. The event may be a `MouseEvent` rather than a `PointerEvent`. - `'none'`: the highlight changed for another reason, such as automatic highlighting while filtering, the item list changing, or the popup opening or closing. | - |
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 | booleanWhether the menu is currently open. | - |
orientation | "horizontal" | "vertical"The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys. | 'vertical' |
MenubarSubTrigger
| Prop | Type | Default |
|---|---|---|
closeDelay | numberHow long to wait before closing the menu that was opened on hover. Specified in milliseconds. | 0 |
delay | numberHow long to wait before the menu may be opened on hover. Specified in milliseconds. | 100 |
disabled | booleanWhether the component should ignore user interaction. | false |
id | string@ignore | - |
inset | booleanIndents the text to line up with items that have a leading icon. | - |
label | stringOverrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided. | - |
nativeButton | booleanWhether 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>`). | true |
onClick | ((event: BaseUIEvent<MouseEvent<HTMLDivElement, MouseEvent>>) => void) | - |
openOnHover | booleanWhether the menu should also open when the trigger is hovered. | true |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuSubmenuTriggerState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. | - |
MenubarSubContent
| Prop | Type | Default |
|---|---|---|
align | "center" | "start" | "end"How to align the popup relative to the specified side. | start |
alignOffset | number | OffsetFunctionAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. | 0 |
finalFocus | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)Determines the element to focus when the menu is closed. | - |
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. | - |
side | "left" | "right" | "top" | "bottom" | "inline-end" | "inline-start"Which side of the anchor element to align the popup against. May automatically change to avoid collisions. | bottom |
sideOffset | number | OffsetFunctionDistance 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. | 0 |