suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

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.

import {
  ClipboardTextIcon,
  CopyIcon,
  ScissorsIcon,
  TrashIcon,
} from "@phosphor-icons/react"
import {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarRadioGroup,
  MenubarRadioItem,

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

$ pnpm dlx shadcn@latest add @esuiss/menubar

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add menubar
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react
  1. Add the pieces it builds on: Dropdown Menu.

  2. Copy and paste the following code into your project.

components/ui/menubar.tsx
"use client"

import { Menu as MenuPrimitive } from "@base-ui/react/menu"
import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar"
import { CheckIcon } from "@phosphor-icons/react"
import type * as React from "react"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuPortal,
  DropdownMenuRadioGroup,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  1. Update the import paths to match your project setup.

Usage

import {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarPortal,
  MenubarRadioGroup,
  MenubarRadioItem,
  MenubarSeparator,
  MenubarShortcut,
  MenubarSub,
  MenubarSubContent,
  MenubarSubTrigger,
  MenubarTrigger,
} from "@/components/ui/menubar"
<Menubar>
  <MenubarMenu>
    <MenubarTrigger>File</MenubarTrigger>
    <MenubarContent>
      <MenubarGroup>
        <MenubarItem>
          New tab
          <MenubarShortcut mod>T</MenubarShortcut>
        </MenubarItem>
        <MenubarItem disabled>New private window</MenubarItem>
      </MenubarGroup>
      <MenubarSeparator />
      <MenubarSub>
        <MenubarSubTrigger>Share</MenubarSubTrigger>
        <MenubarSubContent>
          <MenubarItem>Email link</MenubarItem>
          <MenubarItem>Messages</MenubarItem>
        </MenubarSubContent>
      </MenubarSub>
    </MenubarContent>
  </MenubarMenu>
  <MenubarMenu>
    <MenubarTrigger>View</MenubarTrigger>
    <MenubarContent>
      <MenubarCheckboxItem defaultChecked>
        Show bookmarks bar
      </MenubarCheckboxItem>
      <MenubarSeparator />
      <MenubarItem inset>Reload</MenubarItem>
    </MenubarContent>
  </MenubarMenu>
</Menubar>

Examples

By default

Set defaultOpen on a MenubarMenu to open it on first render. Here the File menu opens with a Share submenu.

import {
  ClipboardTextIcon,
  CopyIcon,
  ScissorsIcon,
  TrashIcon,
} from "@phosphor-icons/react"
import {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarRadioGroup,
  MenubarRadioItem,

Disabled

Set disabled on Menubar to disable the whole bar, so none of its menus open.

import {
  ClipboardTextIcon,
  CopyIcon,
  ScissorsIcon,
  TrashIcon,
} from "@phosphor-icons/react"
import {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarRadioGroup,
  MenubarRadioItem,

Accessibility

  • The bar has the menubar role and each trigger has the menuitem role, with aria-expanded reflecting its menu's state.
  • Popups use the menu role; items use menuitem, menuitemcheckbox or menuitemradio, with aria-checked on 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.

PropTypeDefault
disabledboolean-

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.

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

PropTypeDefault
align"start" | "center" | "end""start"
alignOffsetnumber-4
sideOffsetnumber8

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.

PropTypeDefault
variant"default" | "destructive""default"
insetboolean-

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.

PropTypeDefault
insetboolean-
PropTypeDefault
defaultCheckedbooleanfalse
closeOnClickbooleanfalse

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.

PropTypeDefault
insetboolean-
PropTypeDefault
closeOnClickbooleanfalse

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.

PropTypeDefault
insetboolean-

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.

PropTypeDefault
modboolean-

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.

PropTypeDefault
insetboolean-

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.

NextMessagePreviousMarker

On this page

  1. 01Installation
  2. 02Usage
  3. 03Examples
    • By default
    • Disabled
  4. 04Accessibility
  5. 05API Reference
    • Menubar
    • MenubarMenu
    • MenubarGroup
    • MenubarPortal
    • MenubarTrigger
    • MenubarContent
    • MenubarItem
    • MenubarCheckboxItem
    • MenubarRadioGroup
    • MenubarRadioItem
    • MenubarLabel
    • MenubarSeparator
    • MenubarShortcut
    • MenubarSub
    • MenubarSubTrigger
    • MenubarSubContent