Skip to content
English

How it works

Menus stay inside the closest element marked data-ds-boundary, or the viewport: a menu slides left if it would overflow, a submenu flips to the left, and if neither side fits it stacks over its parent. Hover intent uses a short delay so the pointer can cross items on its way into a submenu.

Use it for

  • Desktop-like tools such as editors and design apps with many commands.
  • Grouping commands that also have keyboard shortcuts.

Look elsewhere when

  • Site navigation between pages: use a navigation menu.
  • Mobile-first screens: use a bottom sheet or a single overflow menu.

Usage

import { useState } from 'react'
import { Menubar } from './Menubar.jsx'

export function EditorMenu() {
  const [ruler, setRuler] = useState(true)
  return (
    <Menubar
      label="Application menu"
      menus={[
        { id: 'file', label: 'File', items: [{ id: 'save', label: 'Save', shortcut: '⌘S', onSelect: save }] },
        {
          id: 'view',
          label: 'View',
          items: [
            { id: 'ruler', type: 'checkbox', label: 'Show ruler', checked: ruler, onCheckedChange: setRuler },
            { type: 'separator' },
            { id: 'zoom', label: 'Zoom', items: [{ id: 'z100', type: 'radio', label: '100%', checked: true }] },
          ],
        },
      ]}
    />
  )
}

Props

PropTypeDefaultWhat it does
menus{ id, label, items: MenuItem[] }[]—Top-level menus in order.
MenuItem{ id, label, shortcut?, disabled?, onSelect?, type?: 'checkbox' | 'radio' | 'separator' | 'label', checked?, onCheckedChange?, items? }—An item; give it items to make a submenu.
labelstring—Accessible name of the menubar.
defaultOpenstring | nullnullId of a menu open on first render.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root.

Accessibility

  • WAI-ARIA menubar pattern: role menubar, menuitem triggers with aria-haspopup and aria-expanded, role menu, menuitemcheckbox and menuitemradio with aria-checked, role separator.
  • Left and Right move between menus (staying open once a menu is open); Down, Enter or Space open and focus the first item, Up the last.
  • Inside a menu Up and Down move, Home and End jump, Right opens a submenu, Left or Escape closes it; Escape on a menu returns focus to its trigger.
  • Roving tabindex keeps the menubar to one Tab stop; disabled items stay focusable but cannot be chosen.
  • Focused items use a solid accent background; triggers show a :focus-visible ring.
  • With reduced motion menus fade without scaling.

Motion

Menus enter 170ms ease-out from 0.97 scale and 3px up; submenus 140ms; switching between open menus is instant.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

Menubar.jsxmenubar.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Navigation