Menubar
Desktop-application menu bar (File, Edit, View) with submenus, shortcut hints and WAI-ARIA menubar keyboard navigation.
<arc-menubar>Overview
Menubar is the row of menus from desktop applications: File, Edit and View, each opening a dropdown of commands. One items array describes it all, set as a property from JavaScript or as a JSON attribute when the menu is static. The component renders the triggers, menus, submenus, dividers and right-aligned shortcut hints.
An entry with its own items array becomes a submenu, marked with a caret. Submenus go one level deep. They open to the right of their parent and flip to the left when they would overflow the viewport. { divider: true } renders a separator line, keyboard navigation skips disabled entries, and shortcut strings show in muted monospace. Shortcuts are display only: the component doesn't bind any keys.
Interaction follows the WAI-ARIA menubar pattern. The bar is a single tab stop with roving focus: ArrowLeft and ArrowRight move across top-level items, ArrowDown or Enter opens a menu, and ArrowUp opens it on the last item. Inside a menu, the arrows move and wrap past dividers and disabled items, ArrowRight enters a submenu, ArrowLeft steps back out (or over to the previous top-level menu), typing a letter jumps to the next item that starts with it, and Escape closes one level at a time and returns focus to the trigger. With a pointer, clicking a trigger toggles its menu, hovering another trigger switches menus once one is open, and hovering a submenu parent opens it after a short delay. Activating a leaf fires arc-select with the label path from root to leaf.
Guidelines
Do
- Group related commands with `{ divider: true }` entries
- Make `shortcut` strings match your real key bindings. You register the bindings yourself
- Keep top-level labels to one word (File, Edit, View)
- Route commands by the label path in `arc-select`
Don't
- Don't use it for site navigation. Use Navigation Menu or Top Bar. A menubar is for application commands
- Don't put destructive actions right next to common ones without a divider between them
- Don't use more than 7 or 8 top-level menus. Move rare commands into a submenu
Features
- Roles are `menubar`, `menu` and `menuitem`, with a roving tabindex
- Home and End jump to the first and last item, and Space activates an item like Enter
- Typing a letter also works on the bar itself when no menu is open
- Submenus open after about 150ms of hover
- `arc-select` puts the path in `detail.path`, such as `["File", "Export", "PNG"]`
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-menubar id="app-menubar"></arc-menubar>
<script>
const menubar = document.getElementById('app-menubar');
menubar.items = [
{ label: 'File', items: [
{ label: 'New File', shortcut: '⌘N' },
{ label: 'Open…', shortcut: '⌘O' },
{ divider: true },
{ label: 'Export', items: [
{ label: 'PNG' },
{ label: 'SVG' }
] }
] },
{ label: 'Edit', items: [
{ label: 'Undo', shortcut: '⌘Z' },
{ label: 'Redo', shortcut: '⇧⌘Z', disabled: true }
] }
];
menubar.addEventListener('arc-select', (e) => {
console.log('command:', e.detail.path); // e.g. ['File', 'Export', 'PNG']
});
</script>import { Menubar } from '@arclux/arc-ui-react';
const items = [
{ label: 'File', items: [
{ label: 'New File', shortcut: '⌘N' },
{ label: 'Open…', shortcut: '⌘O' },
{ divider: true },
{ label: 'Export', items: [
{ label: 'PNG' },
{ label: 'SVG' }
] }
] },
{ label: 'Edit', items: [
{ label: 'Undo', shortcut: '⌘Z' },
{ label: 'Redo', shortcut: '⇧⌘Z', disabled: true }
] }
];
<Menubar
items={items}
onArcSelect={(e) => console.log('command:', e.detail.path)}
/><script setup>
import { Menubar } from '@arclux/arc-ui-vue';
const items = [
{ label: 'File', items: [
{ label: 'New File', shortcut: '⌘N' },
{ divider: true },
{ label: 'Export', items: [{ label: 'PNG' }, { label: 'SVG' }] }
] },
{ label: 'Edit', items: [
{ label: 'Undo', shortcut: '⌘Z' }
] }
];
</script>
<template>
<Menubar :items="items" @arc-select="(e) => console.log(e.detail.path)" />
</template><script>
import { Menubar } from '@arclux/arc-ui-svelte';
const items = [
{ label: 'File', items: [
{ label: 'New File', shortcut: '⌘N' },
{ divider: true },
{ label: 'Export', items: [{ label: 'PNG' }, { label: 'SVG' }] }
] },
{ label: 'Edit', items: [
{ label: 'Undo', shortcut: '⌘Z' }
] }
];
</script>
<Menubar {items} on:arc-select={(e) => console.log(e.detail.path)} />import { Component } from '@angular/core';
import { Menubar } from '@arclux/arc-ui-angular';
@Component({
imports: [Menubar],
template: `
<arc-menubar [items]="items" (arcSelect)="onSelect($event)"></arc-menubar>
`,
})
export class AppMenubarComponent {
items = [
{ label: 'File', items: [
{ label: 'New File', shortcut: '⌘N' },
{ divider: true },
{ label: 'Export', items: [{ label: 'PNG' }, { label: 'SVG' }] }
] },
{ label: 'Edit', items: [
{ label: 'Undo', shortcut: '⌘Z' }
] }
];
onSelect(e: CustomEvent) {
console.log(e.detail.path);
}
}API
itemsArray<{label:string,disabled?:boolean,items:Array<{label?:string,shortcut?:string,disabled?:boolean,divider?:boolean,items?:Array<{label:string,shortcut?:string,disabled?:boolean}>}>}>[]- The menu structure. Entries with an
itemsarray become submenus (one further nesting level supported);{ divider: true }renders a separator. Set as a property, or as a JSON attribute for a menu structure that is static.
Events
arc-select- Fired when a leaf menu item is activated.
detail.pathis the array of labels from the top-level menu to the selected leaf, e.g.["File", "Export", "PNG"].
See also
- Dropdown MenuA menu of actions that opens from a button.
- Context MenuReplaces the browser's right-click menu inside one element with a menu of your own items.
- Top BarThe header bar across the top of an app, with the brand on the left and user controls on the right.
- Command BarSearch input that stays visible in a top bar or toolbar. The border turns accent-colored with a glow ring on focus.