Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Overlays

Menubar

A desktop application's menu bar: a row of titles (File, Edit, View), each opening a Menu of commands. Once one menu is open, the arrow keys and the pointer move straight between menus, as in a native app.

Keyboard moves between menus

When to useLink to "When to use"

  • The application menu of an installed or desktop-style app, usually in its title bar.
  • Many commands in a few familiar groups, where people expect File, Edit and View.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { Menubar } from "@arshad-shah/cynosure";
import { copy, folder, save } from "@arshad-shah/cynosure/icons";

<Menubar
  label="Application"
  menus={[
    {
      label: "File",
      items: [
        { value: "open", label: "Open", icon: folder, shortcut: "mod+o" },
        { value: "save", label: "Save", icon: save, shortcut: "mod+s", disabled: !dirty },
      ],
    },
    { label: "Edit", items: [{ value: "copy", label: "Copy", icon: copy, shortcut: "mod+c" }] },
    { label: "View", items: [{ value: "wrap", label: "Word wrap", kind: "checkbox", checked: wrap }] },
  ]}
  onSelect={(value) => run(value)}
/>

Each menu's items are exactly what Menu takes: icons, shortcuts (shown with Kbd and exposed as aria-keyshortcuts; bind the keys yourself with useHotkey), disabled, tone, checkable kinds, sections (labelled or not) and submenus (an item with items). onSelect receives the chosen item's value from whichever menu, so keep values unique across menus.

Moving between menusLink to "Moving between menus"

While a menu is open, hovering another title opens that menu instead, and so does tapping it. At rest, hovering opens nothing.

Pointer hover switches while open

PropsLink to "Props"

Every prop of Menubar
PropWhat it doesTypeDefault
labelRequired
Accessible name of the bar (required: a menubar must be named).string
menusRequired
The top-level menus, in reading order.MenubarMenu[]
onSelectRequired
Called with the chosen item's value, from whichever menu.(value: string) => void
size
Size of the menu titles (shared vocabulary: docs/conventions.md). Default "md".Size"md"
className
Added to the bar, for layout.string
style
Layout only. Restyle through --cy-menubar-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
TabEnters the bar on one title (the one last used); Tab again leaves it
Left arrow / Right arrow arrows on a titleMove between titles, wrapping
Home / End on a titleFirst / last title
Down arrow, Enter, Space or click on a titleOpens its menu on the first item
Up arrow arrow on a titleOpens its menu on the last item
Left arrow / Right arrow arrows in an open menuClose it and open the neighbouring menu, on its first item
Right arrow arrow on an item with a submenu (Left arrow in RTL)Opens the submenu on its first item; the bar stays on this menu
Left arrow arrow in a submenu (Right arrow in RTL)Closes the submenu, back to its parent item
Up arrow, Down arrow, Home, End, a letterMove inside the open menu, as in Menu
Enter, Space or click on an itemRuns it, closes the menu and returns focus to its title (checkable items stay open)
EscapeCloses the menu and returns focus to its title
Tab / Shift+Tab in an open menuCloses it and leaves the bar
Click outsideCloses the menu
  • Roles: menubar named by label, with aria-orientation="horizontal"; each title is a menuitem with aria-haspopup="menu", aria-expanded and aria-controls naming its menu, which is named after the title.
  • One menu at a time: opening one closes the other.
  • Right to left: in an RTL page the bar reads from the right, and Left and Right swap.
  • Shadow DOM: works inside a shadow root (keys, focus return and outside clicks).
  • Layers: the menus use the shared overlay stack, so inside a dialog Escape closes only the open menu.

TouchLink to "Touch"

Each title's hit area is at least 24px, and 44px on coarse pointers; menu rows are 44px tall there. A tap opens a menu, a tap on another title switches to it and a tap on an item runs it.

ThemingLink to "Theming"

Tokens: --cy-menubar-height, --cy-menubar-padding-inline, --cy-menubar-radius, --cy-menubar-active-bg (hovered title and the open menu's title) and --cy-menubar-gap. The menus are Menu's, themed with --cy-menu-*.

ts
Copy
createTheme({ components: { menubar: { height: "28px", radius: "4px" } } });

Menu · ContextMenu · Toolbar · CommandPalette · Kbd

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog