Menubar

Web

A visually persistent menu common in desktop applications.

Installation

pnpm dlx cubix-ui@latest add menubar --base radix

Usage

Import
import {
  Menubar,
  MenubarContent,
  MenubarItem,
  MenubarMenu,
  MenubarSeparator,
  MenubarTrigger,
} from "@/components/cubix/menubar"
Example
<Menubar dir="rtl" lang="fa">
  <MenubarMenu>
    <MenubarTrigger>پرونده</MenubarTrigger>
    <MenubarContent>
      <MenubarItem>زبانه جدید</MenubarItem>
      <MenubarItem>پنجره جدید</MenubarItem>
      <MenubarItem disabled>پنجره ناشناس</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>چاپ</MenubarItem>
    </MenubarContent>
  </MenubarMenu>
  <MenubarMenu>
    <MenubarTrigger>ویرایش</MenubarTrigger>
    <MenubarContent>
      <MenubarItem>واگرد</MenubarItem>
      <MenubarItem>بازگردانی</MenubarItem>
      <MenubarSeparator />
      <MenubarItem>برش</MenubarItem>
      <MenubarItem>کپی</MenubarItem>
      <MenubarItem>جای‌گذاری</MenubarItem>
    </MenubarContent>
  </MenubarMenu>
</Menubar>

Composition

Each MenubarMenu pairs a trigger with its content. The bar reads dir and lang from the closest ancestor, lays out triggers from the start edge (the right in RTL), and carries the locale into the portaled menus.

Structure
Menubar
├── MenubarMenu
│   ├── MenubarTrigger
│   └── MenubarContent
│       ├── MenubarItem
│       ├── MenubarSeparator
│       ├── MenubarCheckboxItem
│       ├── MenubarRadioGroup
│       │   └── MenubarRadioItem
│       └── MenubarSub
│           ├── MenubarSubTrigger
│           └── MenubarSubContent
└── MenubarMenu
    ├── MenubarTrigger
    └── MenubarContent

Accessibility

The bar is a menubar with roving focus between triggers. Each trigger exposes aria-haspopup and aria-expanded, each content is a menu, and checkbox and radio items announce their checked state.

KeyAction
ArrowLeft / ArrowRightMoves focus between menu triggers in reading direction. With a menu open, opens the neighboring menu instead.
Enter / Space / ArrowDownOn a trigger, opens its menu and focuses the first item.
ArrowDown / ArrowUpMoves focus to the next or previous item.
Home / EndMoves focus to the first or last item.
Enter / SpaceActivates the focused item. Checkbox and radio items toggle and keep the menu open.
EscapeCloses the menu and returns focus to its trigger.

Examples

Basic

Split sections with MenubarSeparator. Set disabled on an item to lock it.

Icons

Place an icon before the label inside MenubarItem or MenubarSubTrigger. It sits at the start of the item (the right side in RTL).

Submenu

Nest menus with MenubarSub, MenubarSubTrigger, and MenubarSubContent. In RTL the submenu opens to the left and ArrowLeft opens it from the keyboard.

Checkboxes

Use MenubarCheckboxItem for options that turn on and off. The menu stays open while toggling.

Checkboxes with icons

Icons sit before the label; the checkbox control stays at the end of the item.

Radio

Use MenubarRadioGroup with MenubarRadioItem for exclusive choices.

Tick indicator

Set indicator="check" to show a plain tick instead of the Cubix Checkbox or Radio. The default is "control". On a radio group it applies to every item in the group.

Sides

Use the side prop on MenubarContent to control placement.

API Reference

Note: Parts render data-slot attributes (menubar, menubar-menu, menubar-trigger, menubar-content, menubar-item, menubar-checkbox-item, menubar-radio-group, menubar-radio-item, menubar-separator, menubar-sub-trigger, menubar-sub-content) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

Menubar

PropTypeDefaultDescription
dir"ltr" | "rtl"-Text direction. Portaled menus inherit this so RTL layout and alignment stay correct.
langstring-Document language on the menubar and portaled content (e.g. "fa"). Enables IRANSans metrics and zero letter-spacing for Arab script.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-One or more MenubarMenu elements.

MenubarTrigger

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-The trigger label shown in the menubar.

MenubarContent

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side of the trigger to render the menu on.
align"start" | "center" | "end""start"Alignment along the opposite axis of side.
sideOffsetnumber8Distance in pixels between the trigger and the menu.
alignOffsetnumber-4Offset in pixels along the alignment axis.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

MenubarItem

PropTypeDefaultDescription
insetboolean-Adds start padding to align with items that have indicators.
variant"default" | "destructive""default"Visual style of the menu item.
disabledboolean-Disables the menu item.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

MenubarCheckboxItem

PropTypeDefaultDescription
checkedboolean-Controlled checked state of the checkbox item.
defaultCheckedboolean-Initial checked state when uncontrolled.
indicator"check" | "control"-What shows when checked: the Cubix Checkbox ("control", default) or a plain tick ("check").
insetboolean-Adds start padding for alignment.
disabledboolean-Disables the checkbox item.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

MenubarRadioGroup

PropTypeDefaultDescription
valuestring-Controlled value of the selected radio item.
defaultValuestring-Initial value when uncontrolled.
indicator"check" | "control"-Indicator for every item in the group: the Cubix Radio ("control", default) or a plain tick ("check"). An item's own indicator prop overrides it.
onValueChange(value: string) => void-Called when the selected value changes.

MenubarRadioItem

PropTypeDefaultDescription
valuestring-Value of this item. It is selected when it matches the group value.
indicator"check" | "control"-Overrides the group indicator for this item: the Cubix Radio ("control") or a plain tick ("check").
insetboolean-Adds start padding for alignment.
disabledboolean-Disables the radio item.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).