Skip to content

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.

<script>
import Menubar from "@invisible-ui/svelte/Menubar.svelte";
</script>

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)}
/>
PropTypeDefaultDescription
label *string—Accessible name for the menubar.
menus *MenubarMenu[]—Top-level menus: { value, label, items, disabled? }.
onSelect((menuValue: string, itemValue: string) => void) | undefinedundefinedCalled when an item is activated.
  • role="menubar" with role="menuitem" triggers (aria-haspopup="menu") and role="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).
<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-*.