Menubar

An application menu bar such as File, Edit and View: a row of menus that act as one widget, with one Tab stop and the arrow keys between them. Its menus are the same as the Menu's, and on narrow layouts the bar collapses into a single Menu button.

  • vig-menubar
Import
import { Menubar } from '@vigdx/ui/menu';

Basic

Pass the top-level menus as items ; each one's items is its menu, with the same entries as vig-menu : submenus, separators, shortcuts, groups and checkable items. A top-level item without items acts directly. selected emits every activated item, and each item's run runs too.

Last command: none

Collapsing on narrow layouts

When the bar itself is narrower than collapse ( sm 30rem by default, md 40rem, lg 48rem, or never ), it shows one Menu button that opens the same items, the top-level menus as submenus. It is a CSS container query, so a server-rendered page shows the right form before any script runs. The bar fills the space it gets ( flex: 1 in a flex row); inside a shrink-to-fit parent, give it a width.

Space for the bar

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="menu"][data-part="menubar"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="menu"]

Menubar styling hooks
Part Element data-state
menubar The role="menubar" row of top-level items. —
menubar-item A top-level <button> or <a> ( role="menuitem" ). open, closed
menubar-trigger The button a narrow menubar collapses into ( collapse ). —
panel A role="menu" panel (also each submenu), in the overlay container. —
item A menu item, <a> or <button> : open / closed with a submenu, checked / unchecked when checkable. open, closed, checked, unchecked
icon The item icon. —
label The item text. —
indicator The check mark or radio dot of a checkable item. —
shortcut The <kbd> of an item's shortcut . —
submenu-indicator The chevron of an item that opens a submenu. —
group A role="group" of items sharing a group heading. —
group-heading The heading of a group. —
separator A separator <hr> . —
Menubar data attributes
Attribute Meaning
data-opening On the overlay element (panel or <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities.
data-closing On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with data-closing: utilities.

Accessibility

  • Follows the WAI-ARIA APG menubar pattern: a role="menubar" named by labels.ariaLabel (“Application menu” by default) of role="menuitem" items; those with a menu have aria-haspopup="menu" and aria-expanded, and their menu is labelled by them.
  • The bar is one Tab stop (a roving tab index). ArrowLeft and ArrowRight move between its items and wrap, Home and End jump, typing a letter moves to the next item starting with it; in right-to-left pages the arrows are mirrored. ArrowDown or Enter opens a menu on its first item, ArrowUp on its last.
  • While a menu is open, ArrowLeft and ArrowRight close it and open the adjacent one with focus on its bar item (ArrowDown then enters it), from the bar or from inside the menu; pointing at another bar item switches to its menu, without animation. Escape closes the menu and returns to its bar item; Tab closes it and leaves the bar.
  • Inside the menus everything works as in the Menu: submenus, typeahead, checkbox and radio items, and every menu closes once an item is activated.
  • The collapsed form is a menu button (aria-haspopup="menu") named by labels.triggerLabel.
  • Use a menubar for application commands. For site navigation, prefer links your users Tab through, such as the Sidebar.

API

Menubar

vig-menubar component

Application menu bar (File, Edit, View) following the APG menubar pattern: one Tab stop, ArrowLeft/ArrowRight between the top-level items (mirrored in RTL), ArrowDown opens a menu, typing jumps to an item, and once a menu is open, the arrow keys and the pointer switch between menus. Its menus are the same panels as vig-menu's, with submenus, groups and checkbox and radio items. Narrower than collapse, it becomes a single "Menu" button opening the same items, decided by CSS alone, so a server-rendered page shows the right one from the start.

Example :
<vig-menubar [items]="menus" (selected)="log($event)" />

While it plays its entrance or exit transition, the animating element carries data-opening or data-closing (stable hooks for styling and for waiting in tests; see the theming guide). data-opening data-closing

Menubar props
Name Type Default Description
collapseMenubarCollapse'sm'

Bar width below which it collapses into one button.

itemsreadonly MenuItem[][]

Top-level items; each one's items is its menu. Others act directly.

labelsPartial<MenubarLabels>—

Texts of the bar and its collapsed button (i18n); locale defaults.

Are you sure?