Menubar
ProThe application menu bar — File · Edit · View. One tab stop with a roving tabindex; Down, Enter or Space opens a menu with its first item highlighted (Up with its last); Left/Right between menus carries the open menu along; Home and End move along the bar when closed and through the items of the open menu when open; hover switches only once something is open; and first-letter type-ahead. The panels are Dropdown Menu, so portalling, flipping and the in-panel keyboard model are shared rather than copied.
import { SvMenubarComponent } from '@styloviz-pro/overlays/menubar';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
The menus
Checkbox items that keep the menu open
Opened from your own shortcut
Letting the bar own its shortcuts
When to use
An application shell that needs File / Edit / View — an editor, an IDE-like tool, a design surface. A dense toolbar where the same commands need keyboard access and a discoverable home. For a single button that drops a list of actions, use Dropdown Menu. For right-click, use Context Menu.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| menus | readonly MenubarMenu[] | [] | The top-level menus, left to right. |
| size | MenubarSize | 'md' | Type scale and density. |
| menuSize | DropdownMenuSize | 'md' | Panel size passed through to each `sv-dropdown-menu`. |
| ariaLabel | string | 'Application' | Accessible name of the bar itself, e.g. `Editor`. A page with more than one menubar — an app bar plus a per-panel one — is two unnamed "menu bar"s in the landmark list without this. |
| disabled | boolean | false | Nothing in the bar opens. |
| customClass | string | '' | Extra classes on the bar. |
| collapseBelow | number | null | null | Viewport width, in px, at or below which the bar collapses into ONE "Menu" button whose menu lists every top-level menu as a submenu. `null` keeps the bar at every width. |
| registerShortcuts | boolean | false | Register every item's `keys` so pressing one fires `(itemClick)`. |
| shortcutScope | SvShortcutScope | 'global' | Which band the item bindings register in. |
| openMenuId | string | null (two-way) | null | The open menu, or `null`. Two-way bindable, so a host can open one from a shortcut of its own (`Alt+F`) or close everything on route change. ONE id rather than a flag per menu: two menus open at once is not a state this widget has, and modelling it as a set would make it representable. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| itemClick | MenubarItemClick | An item was chosen, with the menu it came from. |
| opened | string | The bar opened a menu (any means). |
| closed | void | Everything closed. |
| shortcutConflicts | readonly MenubarShortcutConflict[] | Two or more items declare the same binding. Reported whether or not `registerShortcuts` is on: two File-menu items both claiming ⌘N is a bug in the menu definition either way, and only one of them could ever run from it. |
| openMenuIdChange | string | null | Emits the new `openMenuId` whenever it changes — the output half of `[(openMenuId)]`. |
Customization & theming
Feed `menus` with either flat `items` or `groups` per menu — the same item shape Dropdown Menu takes, including icons, shortcuts, badges, dividers, checkbox/radio types and `danger`. `size` sets the bar's own density; `menuSize` is passed through to the panels. Two-way bind `[(openMenuId)]` to open a menu from a shortcut of your own or close everything on navigation. `disabled` on the bar or on a single menu; disabled menus are skipped by the arrow keys rather than focused and refused. Shortcuts it actually owns: an item's `keys` (`'mod+n'`) renders itself for the running platform, and `[registerShortcuts]` binds it through the shared registry, where `[shortcutScope]` decides whether an overlay's binding outranks it. Duplicates are reported through `(shortcutConflicts)` whether or not anything is bound. Off by default, because an app with a menubar has usually bound these keys already. Menus can cascade: any item with `children` opens a submenu (the Dropdown Menu contract). ArrowRight on such an item opens it and ArrowLeft inside it closes it — the bar only moves between menus when the open menu has nothing to do with the key. Submenu items with `keys` register and collide like any other item. Narrow widths: the bar never pushes the page wider — it scrolls sideways inside itself (`max-w-full overflow-x-auto`; the panels are portalled, so nothing is clipped). `[collapseBelow]="640"` goes further: at or below that viewport width the bar becomes ONE "Menu" button whose menu lists every top-level menu as a submenu, each a bottom sheet with a Back row on a phone — everything opens by tap, nothing needs hover. Picks still arrive through `(itemClick)` with their `menuId`. `collapsed()` reports the state.
Best practices
Do: Keep top-level labels to one word — they are targets on a shared row, and the first letter is the type-ahead key. Do: Give every item `keys` (e.g. `'mod+n'`) rather than a `shortcut` glyph string — the menu bar is where users go to LEARN shortcuts, and `keys` renders itself as ⌘N or Ctrl N for the platform they are actually on. `shortcut` is display-only, binds nothing, and shows ⌘N to a Windows user exactly as typed. Do: Turn on `[registerShortcuts]` if the app does not already bind these keys itself, so the bar arbitrates what it draws instead of just drawing it. Duplicate `keys` are reported through `(shortcutConflicts)` either way — two items both claiming ⌘N is a bug in the menu definition, and only one of them could ever run. Do: Set `keepOpen` on checkbox items so a run of toggles does not slam the menu shut on the first one. Don't: Don't use it as navigation — a menubar announces itself as commands, not as links: items are reached by arrow keys instead of Tab and are missing from a screen reader's links list. Use Mega Menu or a nav bar inside a `<nav>` for going places. In dev mode the bar warns when any item has an `href`. Don't: Don't reach for a menubar to expose one or two actions — it is a commitment to an application keyboard model (roving tabindex, type-ahead, cross-menu arrows). Two buttons are two buttons.
Accessibility
A real `role="menubar"` owning `role="menuitem"` buttons — the Dropdown Menu trigger wrapper is made presentational so the ownership assistive technology walks is not broken by a layout div. ONE tab stop for the whole bar via a roving tabindex; Left/Right move between menus (wrapping, skipping disabled), Home/End jump to the ends, Down/Enter/Space open, Escape closes and returns focus to the trigger. With a menu open, moving along the bar carries the open menu with it — and the keys the open panel owns (Up/Down, Enter, type-ahead over items) are left to the panel rather than handled twice. The panel keeps DOM focus on the trigger and moves a virtual cursor, so `aria-activedescendant` and `aria-owns` are published from the trigger button — the element that actually has focus.
Feedback on Menubar
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.