Fragiola

API: components

Menubar

A bar of menus that is one tab stop, the arrows and the pointer moving from one menu to the next (the APG menubar), in each framework.

A persistent bar of menu buttons, an application's "File, Edit, View" (WAI-ARIA APG menubar pattern, with Base UI's Menubar API). Menubar is one component, not a namespace: its items are the Menu.Triggers of the Menus you place inside it, and everything a Menu has works there: items, groups, checkbox and radio items, submenus.

App menu bar
Gallery

Behaviour

  • One tab stop: exactly one item of the bar has tabindex="0": the first one, then the one that last had focus. Tab enters the bar there and leaves it at once.
  • Arrows: ArrowRight and ArrowLeft in a horizontal bar (mirrored in RTL), ArrowDown and ArrowUp in a vertical one, Home and End, wrapping with loopFocus. ArrowDown, ArrowUp, Enter and Space open an item's menu on its first or last item (a vertical bar: ArrowRight, Enter and Space).
  • Moving between menus: while a menu is open, the bar's arrows close it and open the next item's menu with the focus kept on that item (APG); ArrowDown then enters it. In a menu, the bar's next arrow on an item with no submenu (ArrowRight in LTR) moves to the next menu, and the previous arrow moves back from a menu of the bar itself (in a submenu it closes the submenu, as in any Menu).
  • Hover switching: once a menu is open, hovering another item opens its menu at once. A press right after a hover opening (within 500 ms) keeps the menu open.
  • Escape closes the menu and returns the focus to its item; activating an item does too.
  • Disabled items stay focusable (aria-disabled, the APG's rule for menu items) and open nothing; disabled on the bar disables every item.
  • Modal: off by default (the APG menubar is non-modal). With modal, the open menu locks the scroll and blocks the pointer outside, while the bar keeps taking it.
  • Name: the bar is a role="menubar"; name it with aria-label or aria-labelledby.

Anatomy

partelementdata-primitives-partrole
Menubardivmenubar-rootthe menubar; holds the roving tab stop

Its items are Menu.Triggers (menu-trigger, role="menuitem" in a bar) inside Menu.Roots; their menus are Menu's parts and keep Menu's part attributes (menu-popup, menu-item, ...).

Usage

import { Menu } from "@fragiola/primitives-react/menu";
import { Menubar } from "@fragiola/primitives-react/menubar";

<Menubar aria-label="Application">
    <Menu.Root>
        <Menu.Trigger>File</Menu.Trigger>
        <Menu.Portal>
            <Menu.Positioner sideOffset={4}>
                <Menu.Popup>
                    <Menu.Item onClick={create}>New</Menu.Item>
                    <Menu.Item onClick={print}>Print</Menu.Item>
                </Menu.Popup>
            </Menu.Positioner>
        </Menu.Portal>
    </Menu.Root>
    <Menu.Root>
        <Menu.Trigger>View</Menu.Trigger>
        <Menu.Portal>
            <Menu.Positioner sideOffset={4}>
                <Menu.Popup>
                    <Menu.CheckboxItem defaultChecked>Show toolbar</Menu.CheckboxItem>
                </Menu.Popup>
            </Menu.Positioner>
        </Menu.Portal>
    </Menu.Root>
</Menubar>;

Props

It also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Its menus take Menu's props; in a bar, a Menu.Root's modal is the bar's and a Menu.Positioner defaults to side="inline-end" in a vertical bar.

proptypedefaultdescription
orientation"horizontal" | "vertical""horizontal"which arrow keys move between the items, and where the menus open
loopFocusbooleantruewhether the arrow keys wrap around
modalbooleanfalseevery menu of the bar locks the scroll and blocks the pointer outside while open
disabledbooleanfalseevery item is disabled (focusable, opening nothing)

State and part attributes

partattributes
Menubarrole="menubar", aria-orientation, data-orientation, data-disabled; with modal, the inline style pointer-events: auto
Menu.Trigger (in a bar)role="menuitem", the roving tabindex, aria-haspopup="menu", aria-expanded, aria-controls, data-popup-open; disabled: aria-disabled="true" and data-disabled (never disabled)

The menus' attributes are on the Menu page.

Keyboard

keyhorizontalvertical
Tab, Shift+Tabinto and out of the bar (one tab stop); an open menu closesthe same
next itemArrowRight (ArrowLeft in RTL); with a menu open, opens the next item's menuArrowDown
previous itemArrowLeft (ArrowRight in RTL); with a menu open, opens the previous item's menuArrowUp
Home, Endthe first, the last itemthe same
open on the first itemArrowDown, Enter, Space (into an open menu too)ArrowRight (ArrowLeft in RTL), Enter, Space
open on the last itemArrowUp
in a menu: the next arrow on an item with no submenuthe next item's menu
in a menu of the bar: the previous arrowthe previous item's menucloses the menu, back to its item
Escapecloses the menu, the focus on its itemthe same

Exports

entryexports
@fragiola/primitives-react/menubarMenubar, MenubarProps, MenubarState, RenderProp, RovingOrientation
@fragiola/primitives-vue/menubarMenubar, MenubarProps, MenubarState, RenderSlotProps, RovingOrientation
@fragiola/primitives-angular/menubarMenubar, MenubarState, RovingOrientation