Menubar
A horizontal bar of menus (WAI-ARIA menubar pattern), like an application menu (File / Edit / View). Each menu reuses the headless menu; the menubar adds cross-menu navigation.
Import
Section titled “Import”<script> import Menubar from "@invisible-ui/svelte/Menubar.svelte";</script><script setup> import { Menubar } from "@invisible-ui/vue";</script>import { Menubar } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-menubar></ds-menubar>In Elements, assign the menus through the menus property and listen for
select. Its detail names the menu and the item:
<ds-menubar label="Main"></ds-menubar><script type="module"> import "@invisible-ui/elements/define";
const bar = document.querySelector("ds-menubar"); bar.menus = [ { value: "file", label: "File", items: [{ value: "new", label: "New" }] }, { value: "edit", label: "Edit", items: [{ value: "undo", label: "Undo" }] }, ]; bar.addEventListener("select", (event) => run(event.detail.menu, event.detail.value));</script>In React, onSelect names the menu and the item. A menu’s items takes
groups, separators, checkable items and submenus:
<Menubar label="Main" menus={[ { value: "file", label: "File", items: [{ value: "new", label: "New" }] }, { value: "edit", label: "Edit", items: [ { value: "undo", label: "Undo" }, { type: "submenu", value: "find", label: "Find", items: [{ value: "replace", label: "Replace" }] }, ], }, ]} onSelect={(menu, value) => run(menu, value)}/>| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible name for the menubar. |
menus * | MenubarMenu[] | — | Top-level menus: { value, label, items, disabled? }. |
onSelect | ((menuValue: string, itemValue: string) => void) | undefined | undefined | Called when an item is activated. |
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible name for the bar. |
menus * | MenubarMenu[] | — | The top-level menus. |
onSelect | (menuValue: string, itemValue: string) => void | undefined | Called with the chosen item's menu value and item value. |
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible name for the menubar. |
menus * | MenubarMenu[] | — | The top-level menus. |
onSelect | (menuValue: string, itemValue: string) => void | — | Called with the chosen item's menu value and item value, after the menu has closed. |
| Attribute | Reactive | Description |
|---|---|---|
label * | yes | , names the bar |
Reactive attributes re-render the element when they change after the first render.
Properties: menus (MenubarMenu[]: { value, label, items, disabled? }).
Emits: bubbling select CustomEvent with detail.menu and detail.value, after the menu closes.
Accessibility
Section titled “Accessibility”role="menubar"withrole="menuitem"triggers (aria-haspopup="menu") androle="menu"popups. Roving tabindex: only the active trigger is a tab stop.- ArrowLeft/Right move between triggers (wrapping) or, when a menu is open, switch the open menu; Home/End jump to the first/last trigger; ArrowDown / Enter / Space open a menu and focus its first item. Inside a menu, arrows / Home / End / typeahead navigate, Enter activates, Escape closes and returns focus to the trigger. Hovering another trigger while a menu is open switches to it.
- In right-to-left text ArrowLeft/Right swap, so they keep following the reading direction. Moving onto a disabled menu moves focus to its trigger with the tab stop: it is not opened.
- Under a coarse pointer every trigger and item keeps a hit area of at least
44 by 44 (
--ds-metrics-density-touch-min-target-size).
Example
Section titled “Example”<Menubar label="Main" menus={[ { value: "file", label: "File", items: [{ value: "new", label: "New" }] }, { value: "edit", label: "Edit", items: [{ value: "undo", label: "Undo" }] }, ]} onSelect={(menu, item) => run(menu, item)}/>Themeable via --ds-menu-* (shared with DropdownMenu) and --ds-menubar-*.