Skip to content
UI

Menubar

A horizontal row of menus, like the menu bar of a desktop application.

@zenoxai/ui/components/menubarBase UI Markdown
<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>
  )
}
<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.
  • MenubarShortcut only 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.

PropTypeDefault
disabledboolean

Whether the whole menubar is disabled.

false
loopFocusboolean

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

true
modalboolean

Whether the menubar is modal.

true
orientation"horizontal" | "vertical"

The orientation of the menubar.

'horizontal'
renderReactElement<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.

PropTypeDefault
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null

A parent element to render the portal element into.

-
keepMountedboolean

Whether to keep the portal mounted in the DOM while the popup is hidden.

false
renderReactElement<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.

PropTypeDefault
actionsRefRefObject<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.

-
closeParentOnEscboolean

When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.

false
defaultOpenboolean

Whether the menu is initially open.

false
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.

-
disabledboolean

Whether the component should ignore user interaction.

false
handleMenuHandle<unknown>

A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state.

-
highlightItemOnHoverboolean

Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state.

true
loopFocusboolean

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

true
modalboolean

Determines 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.

-
openboolean

Whether 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'
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).

-

MenubarTrigger

PropTypeDefault
closeDelaynumber

How long to wait before closing the menu that was opened on hover. Specified in milliseconds.

0
delaynumber

How long to wait before the menu may be opened on hover. Specified in milliseconds.

100
disabledboolean

Whether the component should ignore user interaction.

false
handleMenuHandle<unknown>

A handle to associate the trigger with a menu.

-
nativeButtonboolean

Whether 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
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.

-

MenubarContent

PropTypeDefault
align"center" | "start" | "end"

How to align the popup relative to the specified side.

start
alignOffsetnumber | OffsetFunction

Additional 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
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)

Determines the element to focus when the menu is closed.

-
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.

-
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
sideOffsetnumber | OffsetFunction

Distance 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

PropTypeDefault
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.

-

MenubarSeparator

PropTypeDefault
orientation"horizontal" | "vertical"

The orientation of the separator.

vertical
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.

-

MenubarLabel

PropTypeDefault
insetboolean

Indents the text to line up with items that have a leading icon.

-

MenubarItem

PropTypeDefault
closeOnClickboolean

Whether to close the menu when the item is clicked.

true
disabledboolean

Whether the component should ignore user interaction.

false
idstring

@ignore

-
insetboolean

Indents the text to line up with items that have a leading icon.

-
labelstring

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

-
nativeButtonboolean

Whether 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.

-
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.

-
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

PropTypeDefault
checkedboolean

Whether the checkbox item is currently ticked.

-
closeOnClickboolean

Whether to close the menu when the item is clicked.

false
defaultCheckedboolean

Whether the checkbox item is initially ticked.

false
disabledboolean

Whether the component should ignore user interaction.

false
idstring

@ignore

-
insetboolean-
labelstring

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

-
nativeButtonboolean

Whether 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.

-
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.

-

MenubarRadioGroup

PropTypeDefault
defaultValueany

The uncontrolled value of the radio item that should be initially selected.

-
disabledboolean

Whether the component should ignore user interaction.

false
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.

-
valueany

The controlled value of the radio item that should be currently selected.

-

MenubarRadioItem

PropTypeDefault
closeOnClickboolean

Whether to close the menu when the item is clicked.

false
disabledboolean

Whether the component should ignore user interaction.

false
idstring

@ignore

-
insetboolean-
labelstring

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

-
nativeButtonboolean

Whether 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.

-
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.

-
value*any

Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected.

-

MenubarSub

PropTypeDefault
actionsRefRefObject<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.

-
closeParentOnEscboolean

When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.

false
defaultOpenboolean

Whether the menu is initially open.

false
disabledboolean

Whether the component should ignore user interaction.

false
highlightItemOnHoverboolean

Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state.

true
loopFocusboolean

Whether 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.

-
openboolean

Whether 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

PropTypeDefault
closeDelaynumber

How long to wait before closing the menu that was opened on hover. Specified in milliseconds.

0
delaynumber

How long to wait before the menu may be opened on hover. Specified in milliseconds.

100
disabledboolean

Whether the component should ignore user interaction.

false
idstring

@ignore

-
insetboolean

Indents the text to line up with items that have a leading icon.

-
labelstring

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

-
nativeButtonboolean

Whether 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)-
openOnHoverboolean

Whether the menu should also open when the trigger is hovered.

true
renderReactElement<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

PropTypeDefault
align"center" | "start" | "end"

How to align the popup relative to the specified side.

start
alignOffsetnumber | OffsetFunction

Additional 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
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)

Determines the element to focus when the menu is closed.

-
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.

-
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
sideOffsetnumber | OffsetFunction

Distance 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