仕組み
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.
向いている場面
- Desktop-like tools such as editors and design apps with many commands.
- Grouping commands that also have keyboard shortcuts.
向かない場面
- Site navigation between pages: use a navigation menu.
- Mobile-first screens: use a bottom sheet or a single overflow menu.
使い方
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 }] },
],
},
]}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
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. |
label | string | — | Accessible name of the menubar. |
defaultOpen | string | null | null | Id of a menu open on first render. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the root. |
アクセシビリティ
- 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.
モーション
Menus enter 170ms ease-out from 0.97 scale and 3px up; submenus 140ms; switching between open menus is instant.
プロジェクトに追加
プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。
Menubar.jsxmenubar.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。