suiss/ui · Component
Menubar
A horizontal bar of menus, like a desktop application's menu bar.
Menubar is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Menubar wraps the menubar primitive of the chosen base and groups several menus into one keyboard-navigable bar. Each MenubarMenu holds a MenubarTrigger and a MenubarContent popup. Inside the content, compose MenubarItem, MenubarCheckboxItem, MenubarRadioGroup with MenubarRadioItem, MenubarLabel, MenubarGroup, MenubarSeparator, MenubarShortcut, and nested submenus built from MenubarSub, MenubarSubTrigger and MenubarSubContent.
Most parts reuse the Dropdown Menu components with menubar styling. Use Menubar for persistent, app-level command menus; use Dropdown Menu for a single menu opened from one button.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
-
Add the pieces it builds on: Dropdown Menu.
-
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
By default
Set defaultOpen on a MenubarMenu to open it on first render. Here the File menu opens with a Share submenu.
Disabled
Set disabled on Menubar to disable the whole bar, so none of its menus open.
Accessibility
- The bar has the
menubarrole and each trigger has themenuitemrole, witharia-expandedreflecting its menu's state. - Popups use the
menurole; items usemenuitem,menuitemcheckboxormenuitemradio, witharia-checkedon checkbox and radio items. - While a menu is open, ArrowLeft and ArrowRight move to the adjacent menu. ArrowRight on a submenu trigger opens the submenu.
- Escape closes the open menu and returns focus to its trigger.
- Disabled items expose
aria-disabled="true".
API Reference
Menubar
The bar that contains the menus and manages keyboard navigation between them.
| Prop | Type | Default |
|---|---|---|
disabled | boolean | - |
Also accepts the props of the primitive part it wraps.
Set disabled to disable every trigger in the bar.
MenubarMenu
Groups one trigger with its popup and holds that menu's open state.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
Also accepts the props of the primitive part it wraps.
Each MenubarMenu accepts the menu root props, such as open, defaultOpen and onOpenChange. Pass open with onOpenChange to control it.
MenubarGroup
Groups related items inside a menu.
Also accepts the props of the primitive part it wraps.
MenubarPortal
Renders menu content into a portal outside the bar.
Also accepts the props of the primitive part it wraps.
MenubarTrigger
The button in the bar that opens its menu.
Also accepts the props of the primitive part it wraps.
MenubarContent
The positioned popup that holds a menu's items.
| Prop | Type | Default |
|---|---|---|
align | "start" | "center" | "end" | "start" |
alignOffset | number | -4 |
sideOffset | number | 8 |
Also accepts the props of the primitive part it wraps.
align sets how the popup lines up with its trigger. alignOffset is the offset in pixels along the alignment axis, and sideOffset the gap in pixels between the trigger and the popup.
MenubarItem
A single command in a menu.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
inset | boolean | - |
Also accepts the props of the primitive part it wraps.
Use variant="destructive" for items that delete or remove something. inset indents the item to align with items that show a leading icon or indicator. Pass disabled to disable a single item.
MenubarCheckboxItem
An item that toggles on and off, with a leading check indicator.
| Prop | Type | Default |
|---|---|---|
inset | boolean | - |
| Prop | Type | Default |
|---|---|---|
defaultChecked | boolean | false |
closeOnClick | boolean | false |
Also accepts the props of the primitive part it wraps.
Use checked or defaultChecked for the checked state. Checkbox items always reserve leading space for their indicator, and inset sets data-inset on the item.
closeOnClick closes the menu when the item is selected.
MenubarRadioGroup
Groups radio items so only one can be selected.
Also accepts the props of the primitive part it wraps.
Use value or defaultValue for the selected item.
MenubarRadioItem
One option in a radio group, with a leading check indicator when selected.
| Prop | Type | Default |
|---|---|---|
inset | boolean | - |
| Prop | Type | Default |
|---|---|---|
closeOnClick | boolean | false |
Also accepts the props of the primitive part it wraps.
Radio items always reserve leading space for their indicator, and inset sets data-inset on the item.
closeOnClick closes the menu when the item is selected.
MenubarLabel
A non-interactive heading for a section of items.
| Prop | Type | Default |
|---|---|---|
inset | boolean | - |
Also accepts the props of the primitive part it wraps.
MenubarSeparator
A thin divider between groups of items.
Also accepts the props of the primitive part it wraps.
MenubarShortcut
A trailing keyboard shortcut hint inside an item.
| Prop | Type | Default |
|---|---|---|
mod | boolean | - |
Also accepts the props of React.ComponentProps<"span">.
Set mod to prepend the platform's primary modifier key. The shortcut is hidden below the md breakpoint.
MenubarSub
The root of a nested submenu.
Also accepts the props of the primitive part it wraps.
MenubarSubTrigger
The item that opens a submenu.
| Prop | Type | Default |
|---|---|---|
inset | boolean | - |
Also accepts the props of the primitive part it wraps.
MenubarSubContent
The popup that holds a submenu's items.
Also accepts the props of the primitive part it wraps.
Each part sets a data-slot, such as menubar-trigger or menubar-item, for styling. Items expose data-variant and data-inset.