Skip to content

GhostMenubar specification ​

Status: Approved pending review.

The approved nested-menu contract covers child menus and switching between top-level menus.

Purpose and user problems ​

GhostMenubar exposes a horizontal menubar (role="menubar") of GhostMenubarMenu children. Each menu is anchored to a top-level role="menuitem" trigger. It composes overlay primitives (useDismissableLayer, useFloating, GhostPortal, useFocusScope, useControllableState, useGhostId) with useGhostMenuCollection and useRovingFocus so applications get WAI-ARIA APG Menubar behavior: one tab stop on the bar, horizontal roving among top-level triggers, opening adjacent menus when a menu is already open, Down/Enter/Space to open, Escape to close and restore trigger focus, Home/End on the bar and in menus, and typeahead in open menus—without reimplementing keyboard wiring.

Non-goals ​

  • Menu button in isolation (GhostDropdownMenu remains the menu-button pattern).
  • Modal dialog, popover disclosure, tooltip, or native <select> semantics.
  • Decorative chrome, swipe gestures, or animation hooks beyond data-state.

Public API ​

Parts and exports ​

Headless exports from @ghostvue/vue:

  • GhostMenubar (role="menubar" root; coordinates menus)
  • GhostMenubarMenu (per-menu open state and context; renderless)
  • GhostMenubarTrigger (top-level menuitem with aria-haspopup="menu")
  • GhostMenubarContent (positioned dismissable floating role="menu")
  • GhostMenubarItem, Group, Label, Separator, CheckboxItem, RadioGroup, RadioItem (same contracts as dropdown menu items)
  • useGhostMenubar, useGhostMenubarMenu (composables)
  • useGhostMenuCollection, getMenuItems, focusFirstMenuItem, focusLastMenuItem, useRovingFocus (shared primitives)
  • Types mirroring dropdown placement/options plus menubar-specific props

Themed exports from @ghostvue/themes: all parts as thin defineComponent wrappers plus ghost-menubar.css via default.css.

Props and configuration ​

GhostMenubar (root) ​

PropTypeDefaultContract
asstring | Component'div'Menubar container element.
dir'ltr' | 'rtl'omittedText direction for horizontal arrow keys.

GhostMenubarMenu (menu root) ​

PropTypeDefaultContract
openboolean | undefinedundefinedControlled open state.
defaultOpenbooleanfalseInitial open in uncontrolled mode.

GhostMenubarTrigger ​

PropTypeDefaultContract
asGhostMenubarTriggerElement'button'Host element; role="menuitem" on the menubar.
disabledbooleanfalseSkips roving; not activatable.

GhostMenubarContent ​

Same floating props as GhostDropdownMenuContent; default placement is 'bottom-start'. Default portal is true.

Item, group, label, separator, checkbox, and radio parts match GhostDropdownMenu* contracts (including v-model on checkbox/radio group).

v-model contracts ​

  • GhostMenubarMenu: open + update:open (v-model:open).
  • Checkbox and radio items: same as dropdown menu. GhostMenubarCheckboxItem takes checked + update:checked (v-model:checked) or modelValue + update:modelValue (v-model); checked wins when both are set.

Events, slots, and exposed methods ​

  • GhostMenubarMenu default slot: { open: boolean, close: () => void }.
  • Focusable parts expose { element, focus, blur }.

State model ​

  • At most one GhostMenubarMenu is open at a time; opening another closes the rest.
  • Binary open/closed per menu; content mounts with v-if="open".
  • data-state on triggers and content; data-part hooks on all parts.

Consumer data ​

No domain collections on the menubar. Checkbox/radio state is consumer-owned via v-model.

Accessibility contract ​

WAI-ARIA APG Menubar pattern with a menu per top-level item.

Semantics ​

  • Menubar root: role="menubar", data-part="root".
  • Trigger: role="menuitem", aria-haspopup="menu", aria-expanded, aria-controls, data-part="trigger".
  • Content: role="menu", tabindex="-1", data-part="content".
  • Items: menuitem / menuitemcheckbox / menuitemradio as in dropdown menu.

Keyboard interaction ​

KeyWhereBehavior
TabMenubarSingle tab stop into the bar; Tab moves out.
ArrowLeft / RightMenubar (trigger)Roving focus among triggers (wrap); if a menu is open, close it and open the adjacent menu.
ArrowDown / Enter / SpaceClosed triggerOpen menu; focus first item (ArrowUp on trigger focuses last item).
Menu keysOpen menuSame as GhostDropdownMenu via useGhostMenuCollection.
Home / EndMenubar triggersFirst / last enabled trigger.
EscapeOpen menuClose; restore focus to owning trigger.

Focus behavior ​

  • useRovingFocus on the menubar root for horizontal trigger roving (one tab stop).
  • On menu open: focusFirstMenuItem / focusLastMenuItem on content after positioned.
  • On dismiss: restore focus to trigger via useFocusScope.

Rendering and customization ​

  • GhostMenubarMenu is renderless; GhostMenubar renders the bar container.
  • Content uses class ghost-menubar-content; themed tokens mirror dropdown menu. Consumer class and style merge with the library class and floating position styles.

Environment behavior ​

SSR and hydration ​

  • useGhostId for SSR-safe IDs; closed menus render triggers only.
  • Overlay composables guard browser APIs in onMounted.
  • SSR hydration fixture with expectSsrHydration.

Mobile and touch ​

  • useDismissableLayer for outside pointer dismissal.

Performance ​

  • Floating and dismiss listeners active only while a menu content is mounted and open.

Composition ​

  • useGhostMenubarMenu reuses useGhostDropdownMenu with menubar-specific ID namespaces.
  • useGhostMenubar registers menus and enforces a single open menu.
  • useRovingFocus on the menubar root; useGhostMenuCollection on each content.

Test plan ​

  • Unit (GhostMenubar.test.ts): controlled/uncontrolled open; single open menu; menubar roving; arrow opens adjacent when open; trigger aria-*; menu roving, typeahead, Escape; checkbox/radio behavior.
  • SSR: closed menubar and overlay-ssr / expectSsrHydration fixture.
  • Theme CSS integration: token-only stylesheet.
  • E2E (ghost-menubar.spec.ts): axe, horizontal navigation, open adjacent, Down open, items, checkbox, radio, Escape.
  • Cross-browser (rtl-roving.spec.ts, @cross-browser): RTL layout order and mirrored arrows between closed triggers with real focus in Chromium, Firefox, and WebKit. No engine differences found; focus and ARIA assertions are shared.
  • Visual: Docker baselines for headless and themed examples.

Documentation plan ​

  • docs/components/menubar.md with headless and themed examples.
  • Executable examples menubar/basic, menubar/themed.

Compatibility and release impact ​

  • Additive minor Changeset for @ghostvue/vue and @ghostvue/themes.

Open architectural questions ​

The shared submenu specification resolves child navigation and top-level switching.