Skip to content

Menubar ​

A desktop-app-style top menu bar (File / Edit / View). Click or hover expands submenus (cascading popups), with arrow key support, Alt access keys and a focus trap.

Multi-group radio (independent checkmarks per group) ​

The value of a type: "group" item acts as a group id. Leaves inside the same group record their selection independently; when value is a JSON object string ({"group-id":"selected"}), groups don't interfere — both "Mode" and "Theme" can show a checkmark at once.

Multi-group radio

mode: preview, theme: dark

Action items (kind: "action") ​

Leaves with kind: "action" render as plain actions (menuitem): no checkmark, clicks do not write back value, and only oas-select is dispatched (detail.kind === "action"). Fits "Open / Save / About" style items. Selecting an action closes the entire cascade by default (desktop menu convention: the menu closes once the action fires); keepOpen: true (the keep-open attribute on the declarative child channel) keeps individual actions open — useful for "Recent files" style lists meant for consecutive picking.

Action items (kind: action) and close-on-select strategy

value: mode (actions don't change it; "Duplicate" is keep-open; the "Bulk" bar uses close-on-select="false" so nothing collapses)

Shortcuts (shortcut) ​

The shortcut field (e.g. "Ctrl+N"): renders a key hint on the right, and auto-binds a document-level keydown — pressing the combo selects that item (preventDefault blocks the browser default). Binding rules: modifier+key combos bind directly; single keys bind only for function keys (F1–F12) — any other single key (letters/digits/Delete etc.) is display-only and not bound.

Global shortcut semantics: both shortcut and accessKey (Alt access keys) are document-level bindings, acting on the whole page rather than only when the menubar is focused. To avoid hijacking input, when focus is inside an editable control (input / textarea / select / contenteditable): defined shortcuts with Ctrl / Cmd, and single-key F1–F24 shortcuts, still fire (so save/new-file actions remain reachable in editors); all other keys (plain printable characters, arrow/editing keys, Alt access keys, and any key during IME composition) yield to the control and the browser; a modifier combination that matches no shortcut is not preventDefaulted, so the editor's own shortcuts keep working; a matched shortcut does not move focus to the menubar, so the editor caret stays where it was. The menubar's own keyboard navigation (arrow keys / Tab focus trap) only acts on its internal focus and is unaffected by this guard. Keep each shortcut unique within the page; conflicts resolve to the first matched menu item. The pass-through granularity is controlled by the editable-shortcuts attribute; editor-style apps can use the shortcuts-in-editable global toggle to pass everything through (both see below).

Pass-through granularity inside editable focus (editable-shortcuts) ​

The editable-shortcuts attribute controls how defined shortcuts pass through while focus is inside an editable control; runtime changes take effect immediately:

ValueBehavior
Default / allCurrent behavior: defined shortcuts with Ctrl / Cmd, and single-key F1–F24 shortcuts, all pass through — Ctrl+S save stays reachable inside editors; the trade-off is described in the warning below
safeAll shortcuts pass through except editing keys. Editing keys = Ctrl/Cmd + C / V / X / A / Z / Y (case-insensitive), which yield to the browser's native copy / paste / cut / select-all / undo / redo; other shapes such as Ctrl+S, Ctrl+N and F-keys still pass through
noneNothing passes through while focus is in an editable control: every defined shortcut (Ctrl/Cmd combos and F-keys alike) yields to the control

Invalid values fall back to all with a one-time development-mode warning. Example:

html
<!-- Editor scenario: Ctrl+S triggers the save menu item; Ctrl+C/V/X/A/Z/Y go to native editing -->
<oas-menubar editable-shortcuts="safe" items='...'></oas-menubar>

Editing-key bindings are still risky under the default all

Under the default all, defined Ctrl / Cmd + editing-key shortcuts (Ctrl+C / Ctrl+V / Ctrl+X / Ctrl+A / Ctrl+Z / Ctrl+Y and their Cmd forms) fire the menu action and call preventDefault inside inputs, hijacking copy / paste / cut / select-all / undo. Editor-style applications should set editable-shortcuts="safe" (editing keys yield, save-style combos stay) or "none" (everything yields inside editable focus); without the attribute, do not bind editing keys to menu actions — to display those hints, handle the key yourself at the host level (leave the component unbound), or use kind: "action" with your own document listener.

Global pass-through toggle inside editable focus (shortcuts-in-editable) ​

The shortcuts-in-editable boolean attribute (off by default): when enabled, all defined shortcuts fire as usual while focus is inside any editable control (input / textarea / select / contenteditable, including editor contentDOMs — contenteditable elements are covered naturally), overriding the editable-shortcuts granularity modes — editor-style applications whose primary surface is the editor use this to explicitly opt out of the mistouch-proof baseline. Off (default) leaves the editable-shortcuts behavior untouched. Runtime changes take effect immediately.

html
<!-- Editor scenario (e.g. CodeMirror 6): Ctrl+S / F9 fire menu actions inside the contentDOM -->
<oas-menubar shortcuts-in-editable items='...'></oas-menubar>
<!-- Combined with the granularity switch: the global toggle wins — safe/none no longer yield inside editable focus -->
<oas-menubar shortcuts-in-editable editable-shortcuts="none" items='...'></oas-menubar>

Shortcuts

Try Ctrl+N / Ctrl+O / Ctrl+S

Basic usage ​

Basic usage

Nothing selected

Disabled items and groups ​

Submenus support disabled, type: "divider" separators and type: "group" group titles.

Disabled items and groups

Nothing selected

Controlled selection ​

The value attribute is controlled (it is in observedAttributes): an external setAttribute('value', ...) takes effect immediately and syncs the selected item (check/highlight) to the corresponding leaf item; internal clicks also write back to value (uncontrolled channel), and the host can listen to oas-select to take over.

Controlled selection (value attribute)

Select "New"Select "Undo"Clear selectionvalue: -

Checkboxes and radio groups (group selections stay open + close-on-select) ​

Leaves with kind: "checkbox" and radio items follow the group-selection semantics: selecting them does not close the submenu (continuous toggling / switching, including the mobile hamburger panel and the "···" overflow popup). kind: "action" items close the entire cascade by default (desktop menu convention). The global switch close-on-select="false" keeps actions open too (whole-menu continuous selection); the item-level keepOpen field keeps individual actions open. close-on-select is a boolean attribute: presence means true (including an empty value); only an explicit "false" disables it — when absent, each kind falls back to its own default semantics.

Checkboxes and radio (group selections stay open)

Checked: ["grid"]

Controlled open (open) ​

The open attribute holds the value of the currently open top-level menu (open="" closes all). Controlled attribute: an external setAttribute('open', ...) opens/switches/closes immediately; internal changes write open back and dispatch oas-open-change (detail: { value, open }) for the host to take over.

Controlled open (open attribute)

Open "File"Open "Edit"Closeopen: -

Trigger mode and arrow-key wrap (trigger / loop) ​

trigger="click" (default): a top-level menu opens on click first; once one is open, hovering another top-level item switches to it (desktop convention). trigger="hover" opens directly on hover. loop="false" disables wrap-around at the edges.

Hover opens directly (trigger)

hover opens directly (no click-first)

No wrap-around (loop)

← stops at the first, → stops at the last

Disabled bar (disabled) ​

disabled disables the whole bar: top-level/sub-item clicks, keyboard navigation, shortcut hotkeys and Alt access keys are all blocked.

Disabled bar (disabled)

The whole bar is inert

side controls the first-level popup side (default bottom), align its alignment (default start), offset the gap to the trigger (px); show-arrow draws a visual arrow pointing at the trigger.

Popup positioning + arrow (side / align / offset / show-arrow)

side=top / align=end / offset=8 / show-arrow

Vertical orientation (orientation) ​

orientation="vertical": the bar stacks vertically, first-level popups default to the right; ↑/↓ move between top-level items, → opens a submenu.

Vertical (orientation)

Mobile hamburger folding (breakpoint) ​

breakpoint="600": when the viewport is ≤ 600px wide the bar folds into a hamburger button + popup menu (narrow-width folding); widen the window to restore the full bar.

Mobile hamburger (breakpoint)

Shrink the window (≤600px) to try the hamburger

Icons (icon) ​

Both top-level items and sub-items accept an icon field (icon-set name); icons follow the text color.

Icons (icon)

Icon color (iconColor) ​

Both top-level items and sub-items accept an iconColor field (fixes the icon color, overriding the selected/disabled default); it defaults to currentColor following the text color. The declarative child channel uses the icon-color attribute.

Icon color (iconColor / icon-color)

Leaves (both inside submenus and top-level leaves) with href render as real <a> links: right-click new window and middle-click open work natively, good for SEO; clicks still dispatch oas-select and write back value (the link's default navigation is not blocked). target="_blank" automatically adds rel="noopener".

Link navigation (real href links)

Clicking a leaf navigates and fires oas-select

Declarative child channel ​

Besides the items JSON, you can write items declaratively with <oas-menubar-item> / <oas-menubar-group> / <oas-menubar-divider> (the items attribute wins when explicitly set; otherwise child elements are parsed and converge to the same render path). The default slot text is the label; attributes map to the MenubarItem fields: value / disabled / icon / kind / danger / href / target / rel / shortcut / access-key / keep-open / indeterminate. Nesting child elements directly inside <oas-menubar-item> recursively becomes a submenu; <oas-menubar-group> uses its label attribute as the group title (value can serve as a radio group id) and flattens its children to the same level. Child additions/removals, attribute and text changes re-render automatically (MutationObserver).

Declarative child channel (group / divider / nesting / checkbox / indeterminate / shortcut / danger / href)

File Project AProject BSaveComponent docsView Select allGridlinesDeleteNothing selected (try Alt+F to open "File", Ctrl+S to trigger Save)

Dynamic add/remove (MutationObserver auto-refresh)

Append a top-level itemFile New

Horizontal overflow folding (···) ​

When the container is too narrow, top-level items that don't fit fold into a trailing "···" item; clicking it opens a popup with the folded items (selecting works). When the selected item is folded, "···" highlights. Only in horizontal mode; vertical and the mobile hamburger don't fold. A folded top-level item that has a submenu is treated as a plain selectable item inside the popup (cascading submenus are not expanded there).

Overflow folding (narrow container)

Container fixed at 380px; overflowing items fold into "···"

Indeterminate checkboxes ​

kind: "checkbox" items support indeterminate: true: they render aria-checked="mixed" with a horizontal dash inside the box (distinct from the ✓ of a fully checked item), for parent/child "partially selected" scenarios. The half-selected state is computed by the host and passed via the items JSON; after toggling, the host can update the items to clear the flag.

Indeterminate checkbox

"Select all" is in the mixed state

Leading/trailing slots (start / end) ​

slot="start" (logo position) / slot="end" (avatar position) decorative slots: rendered inside the bar when they have content; keyboard navigation skips them automatically (not part of arrow keys or the focus trap).

start / end slots (logo / avatar)

Put a logo/graphic in `start` and an avatar in `end`; arrow keys move between menu items and never jump into the slots.

API ​

oas-menubar ​

Attributes ​

AttributeDescriptionTypeDefault
alignFirst-level popup alignment: start (default) / center / end; with side top/bottom it aligns on the horizontal axis, with left/right on the vertical axisstring—
breakpointMobile breakpoint (px, e.g. 600): when the viewport width is ≤ the breakpoint the bar collapses into a hamburger button + popup menu (narrow-width folding)string—
close-on-selectGlobal close switch: selecting a kind:"action" item closes the entire cascade by default (desktop menubar convention); close-on-select="false" keeps actions open too (whole-menu continuous selection); checkbox/radio group selections always stay open regardless of this value (continuous toggling/switching) — use the item-level keepOpen to keep individual actions openstring—
disabledDisable the whole bar: top-level/sub-item clicks, keyboard navigation, shortcut hotkeys and Alt access keys are all blocked; visually desaturatedboolean—
editable-shortcutsPass-through granularity of shortcuts while focus is in an editable control: default / all (defined Ctrl/Cmd shortcuts and F-keys all pass through — the default) / safe (editing keys Ctrl/Cmd + C/V/X/A/Z/Y yield to native browser editing, everything else still passes through) / none (nothing passes through inside editable focus); invalid values fall back to all with a one-time development-mode warning; runtime changes take effect immediatelystring—
itemsTop-level menu items JSON (with submenu children)string[]
loopArrow-key wrap-around toggle, default true (loops at edges); explicit loop="false" stops at the edgesstring—
offsetGap between the first-level popup and its trigger (px, default 4)string—
openValue of the currently open top-level menu (open="" closes all). Controlled attribute (in observedAttributes): an external setAttribute('open', ...) opens/switches/closes immediately; internal click/hover/keyboard changes write it back and dispatch oas-open-change, letting the host take overstring—
orientationArrangement direction: horizontal (default) / vertical (bar stacks vertically, first-level popups default to the right, arrow keys move top-level items up/down)——
shortcuts-in-editableGlobal pass-through toggle for shortcuts inside editable focus (boolean, off by default): when enabled, defined shortcuts fire as usual while focus is inside input / textarea / select / contenteditable (including editor contentDOMs), overriding the editable-shortcuts granularity modes (editor-style apps opt out of the mistouch-proof baseline explicitly); off (default) leaves behavior untouched, runtime changes take effect immediatelystring—
show-arrowShow a visual arrow on the popup pointing at the trigger——
sideFirst-level popup side: bottom (default horizontal) / top / left / right (default vertical); cascading submenus are unaffectedstring—
triggerTop-level menu trigger: click (default, click to open first, then hover switches — desktop convention) / hover (hover opens directly)——
valueSelected value. As a plain string it is a single global selection (no-group scenarios, backward compatible); as a JSON object string (e.g. {"mode":"preview","theme":"dark"}) selections are recorded per group id — the value of a type:"group" item acts as the group id; as a JSON array string (e.g. ["grid","wrap"]) it is the checkbox checked-set (kind:"checkbox" items, multi-select)string—

Events ​

EventDescription
oas-open-changeThe open top-level menu changed, detail: { value, open } (value = currently open top-level menu value, open = whether anything is open). Fired both on controlled setAttribute('open') and internal click/hover/keyboard changes (not on the first frame)
oas-selectAn item was selected, detail: { value, kind?, checked? }. kind only appears for action items (kind: "action"); checkbox items carry checked (new checked state); radio items omit detail.kind

Slots ​

NameDescription
endTrailing decorative slot (e.g. avatar): <div slot="end"> renders when it has content; keyboard navigation skips it
startLeading decorative slot (e.g. logo): <div slot="start"> renders when it has content; keyboard navigation skips it

oas-menubar-item ​

Attributes ​

AttributeDescriptionTypeDefault
access-keyAlt access key (single character); defaults to the first ASCII letter of the label——
dangerDestructive item: danger color semantics (delete/logout operations)——
disabledDisable this item——
hrefLink URL: with href the item renders as a native <a> (real navigation + still fires oas-select)——
iconLeading icon (@oas-ui/icons registry icon name)——
icon-colorIcon color: fixes the icon to this color (overrides the selected/disabled default); defaults to currentColor following the text color——
indeterminateCheckbox indeterminate state: renders aria-checked="mixed" + a dash inside the box (only for kind="checkbox" items)——
keep-openKeep the menu open after selection (only meaningful for kind="action" items): actions close the entire cascade by default, this attribute lets individual actions opt out——
kindLeaf semantics: radio (default, selectable) / action (no checked state, does not write back value, closes the cascade on selection — keep-open opts out) / checkbox (multi-select, value is the checked-set array)——
relLink rel (with href)——
shortcutShortcut hint (e.g. "Ctrl+N"): rendered as a trailing kbd + a document-level keydown binding that triggers select on hit——
targetLink target (with href)——
valueSelection value (data-carrier field of the declarative child channel)——

Slots ​

NameDescription
defaultMenubar item label content (default slot text); direct child <oas-menubar-item>/<oas-menubar-group>/<oas-menubar-divider> elements recursively become the submenu children

oas-menubar-group ​

Attributes ​

AttributeDescriptionTypeDefault
labelGroup title (small secondary text, not clickable)——
valueRadio group id (picking inside the group only updates that group's selected value)——

Slots ​

NameDescription
defaultGroup items: child <oas-menubar-item>/<oas-menubar-group>/<oas-menubar-divider> elements flatten to the same level

oas-menubar-divider ​

Slots ​

NameDescription
defaultDivider data carrier (no attributes; the host parses it as type: "divider")

Event detail note: the detail of oas-select is a component-internal object (value/kind) — not a native Event, so you can't preventDefault() on it or read a native event.target from it. To reach the native event, use the outer parameter of your listener (e.g. in addEventListener('oas-select', (e) => ...), e is a CustomEvent and e.detail is the component data).

MenubarItem fields (inherits MenuItem):

FieldDescriptionType
labelMenu textstring
valueSelection value (declared in the items JSON; after render the host tag carries a data-value lowercased attribute for internal lookup — hosts shouldn't rely on it as public API)string
kindLeaf semantics: radio (default, checkable, participates in value) / action (action item, no checkmark, doesn't write back value on click, closes the cascade on selection — keepOpen opts out)string
shortcutShortcut hint (e.g. "Ctrl+N"); renders as a right-side kbd and auto-binds a document-level keydown (selects the item on match, preventDefault)string
accessKeyAlt access key (single character); defaults to the first ASCII letter of labelstring
keepOpenKeep the menu open after selection (only meaningful for kind:"action" items); the declarative child-channel attribute is keep-openboolean
disabledDisabledboolean
childrenSubmenu items (nested recursively, cascading to the right)MenubarItem[]

Keyboard: at top level ←/→ switch, ↓/Enter opens the submenu, Esc closes; inside a submenu ↑/↓ move, → enters a cascading submenu, ← returns to the parent; Home/End jump. Pressing Alt alone focuses the menu bar, Alt + access key opens the matching top-level menu. While a submenu is open, Tab cycles among its items (focus trap); roving tabindex keeps only the current top-level item tab-reachable.

Released under the MIT OR Apache-2.0 License.