Cómo funciona
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.
Úsalo para
- Desktop-like tools such as editors and design apps with many commands.
- Grouping commands that also have keyboard shortcuts.
Busca otra opción cuando
- Site navigation between pages: use a navigation menu.
- Mobile-first screens: use a bottom sheet or a single overflow menu.
Uso
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 }] },
],
},
]}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
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. |
Accesibilidad
- 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.
Movimiento
Menus enter 170ms ease-out from 0.97 scale and 3px up; submenus 140ms; switching between open menus is instant.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
Menubar.jsxmenubar.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.