Skip to main content

rc-menubar

Menubar coordinator for rc-menu-button children with roving tabindex and submenu handoff, following the WAI-ARIA Menubar pattern.

Package
@rcarls/rc-menubar
Element
<rc-menubar>
Native dependency
Consumer supplies menu buttons and menus
State model
Roving focus and submenu state
Main events
None

Installation​

npm install @rcarls/rc-webcomponents@next
import '@rcarls/rc-webcomponents/rc-menubar/define';

Usage​

Place rc-menu-button elements as direct children, and name the menubar with label.

<rc-menubar label="Application menu">
<rc-menu-button>
<button slot="trigger">File</button>
<rc-menu label="File">
<button>New</button>
<button>Open…</button>
</rc-menu>
</rc-menu-button>
<rc-menu-button>
<button slot="trigger">Edit</button>
<rc-menu label="Edit">
<button>Undo</button>
<button>Redo</button>
</rc-menu>
</rc-menu-button>
</rc-menubar>

Live demo​

Accessibility​

The host has role="menubar", aria-orientation, and an aria-label from label. The triggers share one tab stop through a roving tabindex, and each opens its rc-menu.

KeyAction
Right Arrow (horizontal), Down Arrow (vertical)Focuses the next trigger, wrapping; if a menu is open, opens the next menu instead.
Left Arrow (horizontal), Up Arrow (vertical)Focuses the previous trigger, wrapping; if a menu is open, opens the previous menu.
Home, EndFocuses the first or last trigger.
EscapeCloses the open menu and keeps focus on its trigger.
TabLeaves the menubar.

Left and Right swap in right-to-left text. Inside an open menu, the rc-menu keyboard behavior applies. See the WAI-ARIA Menubar pattern.

Theming​

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

rc-menubar owns the menubar surface and maps --rc-menubar-item-* variables onto each child rc-menu-button trigger. This keeps top-level menubar items flat while standalone menu buttons can keep their own button-like defaults.

Localization​

Built-in text follows the element's own lang, else <html lang>. Override it with messages, or register it for every instance under rc-menubar: label. See Localization.

API​

Properties​

PropertyMarkupTypeDefaultDescription
messagesJS property onlyPartial<RCMenubarMessages> | undefinedNot specifiedBuilt-in text overrides; unset keys fall back to registered text, then English.
labellabelstring | undefinedNot specifiedAccessible label for the `role="menubar"` element. Defaults to the `label` message.
orientationorientation'horizontal' | 'vertical''horizontal'Orientation of the menubar, controls which arrow keys move between items.
$itemsJS property onlyHTMLElement[]Not specifiedAll slotted trigger elements in DOM order.
$menuButtonsJS property onlyRCMenuButton[]Not specifiedAll slotted `rc-menu-button` children in DOM order.
$firstItemJS property onlyHTMLElement | undefinedNot specifiedFirst trigger element in the menubar.
$lastItemJS property onlyHTMLElement | undefinedNot specifiedLast trigger element in the menubar.
$nextItemJS property onlyHTMLElement | undefinedNot specifiedTrigger after `_$lastFocused`, wrapping around to the first.
$previousItemJS property onlyHTMLElement | undefinedNot specifiedTrigger before `_$lastFocused`, wrapping around to the last.

Methods​

MethodDescription
focusItem($item?: HTMLElement | null)Moves focus to a trigger element.
closeActiveMenu()Closes the currently open child menu without returning focus to its trigger.

Slots​

NameDescription
defaultTakes rc-menu-button elements to display in the menubar

CSS Custom Properties​

PropertyDefaultDescription
--rc-menubar-gapvar(--rc-control-gap)Gap between menu buttons
--rc-menubar-padding-inlinevar(--rc-control-padding-inline)Inline-axis padding
--rc-menubar-padding-blockvar(--rc-control-padding-block)Block-axis padding
--rc-menubar-bordervar(--rc-border)Root container border
--rc-menubar-radiusvar(--rc-control-radius)Root container border radius
--rc-menubar-backgroundCanvasRoot container background
--rc-menubar-colorCanvasTextRoot container text color
--rc-menubar-item-block-size2.25emMinimum block size for child menu-button triggers
--rc-menubar-item-padding-block0.25emChild trigger block-axis padding
--rc-menubar-item-padding-inline0.75emChild trigger inline-axis padding
--rc-menubar-item-gapvar(--rc-item-gap)Gap between flex children inside child triggers
--rc-menubar-item-border1px solid transparentChild trigger border
--rc-menubar-item-radiusvar(--rc-control-radius)Child trigger border radius
--rc-menubar-item-backgroundtransparentChild trigger background
--rc-menubar-item-colorinheritChild trigger text color
--rc-menubar-item-transitionNot specifiedCSS transition applied to child triggers
--rc-menubar-item-hover-backgroundcolor-mix(in srgb, Highlight 8%, transparent)Child trigger hover background
--rc-menubar-item-hover-colorinheritChild trigger hover text color
--rc-menubar-item-hover-border-colortransparentChild trigger hover border color
--rc-menubar-item-open-backgroundcolor-mix(in srgb, Highlight 12%, transparent)Child trigger background when its menu is open
--rc-menubar-item-open-colorinheritChild trigger text color when its menu is open
--rc-menubar-item-open-border-colortransparentChild trigger border color when its menu is open

CSS Parts​

PartDescription
rootThe root container element