Skip to content

GhostDropdownMenu specification ​

Status: Approved pending review.

Follow-up (out of scope): see the proposed nested-menu contract.

Purpose and user problems ​

GhostDropdownMenu exposes a floating menu button surface anchored to a trigger. It composes @ghostvue/vue overlay primitives (useDismissableLayer, useFloating, GhostPortal, useFocusScope, useControllableState, and useGhostId) with useGhostMenuCollection so applications get correct menu ARIA, roving item focus, typeahead, collision-safe positioning, portaling, Escape/outside dismissal, and focus restoration without reimplementing menu keyboard behavior or Floating UI wiring.

Non-goals ​

  • Modal dialog behavior (aria-modal="true", scroll lock, or focus trapping).
  • Non-modal disclosure dialog semantics (aria-haspopup="dialog"). Those belong to GhostPopover.
  • Tooltip timing or aria-describedby tooltips (GhostTooltip).
  • Native <select> / listbox semantics (GhostSelect).
  • Submenus (separate trigger inside content that opens a child menu). Tracked as GHO-92 / GHO-107; current content is a flat role="menu" only.
  • Decorative menu icons, swipe gestures, or animation hooks beyond data-state.

Public API ​

Parts and exports ​

Headless exports from @ghostvue/vue:

  • GhostDropdownMenu (root state and context provider; renderless)
  • GhostDropdownMenuTrigger (menu button anchor)
  • GhostDropdownMenuContent (positioned, dismissable floating role="menu")
  • GhostDropdownMenuItem (role="menuitem")
  • GhostDropdownMenuGroup (logical grouping container)
  • GhostDropdownMenuLabel (non-focusable section label)
  • GhostDropdownMenuSeparator (horizontal rule between sections)
  • GhostDropdownMenuCheckboxItem (role="menuitemcheckbox")
  • GhostDropdownMenuRadioGroup / GhostDropdownMenuRadioItem (menuitemradio set with shared selection)
  • useGhostDropdownMenu (composable for open state and IDs)
  • useGhostMenuCollection, getMenuItems, focusFirstMenuItem, focusLastMenuItem (shared menu keyboard utilities)
  • Types: props, exposed handles, context, placement/flip/shift options, and UseGhostDropdownMenuReturn

Themed exports from @ghostvue/themes:

  • All parts above as thin defineComponent h() wrappers plus ghost-dropdown-menu.css via default.css

Props and configuration ​

GhostDropdownMenu (root) ​

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

GhostDropdownMenuTrigger ​

PropTypeDefaultContract
asGhostDropdownMenuTriggerElement (Component | string)'button'Element tag or component (for example GhostButton).
disabledbooleanfalsePrevents toggling when true. Uses native disabled on <button> and aria-disabled on non-button tags.

GhostDropdownMenuContent ​

PropTypeDefaultContract
asGhostDropdownMenuContentElement'div'Menu surface element.
placementPlacement'bottom'Preferred placement relative to the trigger.
offsetOffsetOptions | boolean | undefinedundefinedDistance passed to useFloating.
flipboolean | FlipOptionstrueFlip when overflowing.
shiftboolean | ShiftOptionstrueShift along cross axis.
strategyStrategy'absolute'CSS positioning strategy.
portalbooleantrueTeleport via GhostPortal when true.
portalToGhostPortalTarget'body'Teleport target.

GhostDropdownMenuItem ​

PropTypeDefaultContract
asGhostDropdownMenuItemElement'div'Item element.
disabledbooleanfalseSkipped in roving; not activatable.

Emits select with the activating Event when activated. The menu closes after activation unless the consumer calls event.preventDefault() on that event (or on click for checkbox toggles).

GhostDropdownMenuCheckboxItem ​

PropTypeDefaultContract
checkedbooleanundefinedControlled checked state (v-model:checked).
modelValuebooleanundefinedSame state as checked (plain v-model). checked wins.
defaultCheckedbooleanfalseUncontrolled initial checked.
disabledbooleanfalseSkipped in roving.

Toggles on click or Space / Enter without closing the menu. Each toggle emits update:checked and update:modelValue with the same value, so v-model:checked and plain v-model both work, matching GhostCheckbox and GhostSwitch. The item is controlled when either prop is defined; when both are, checked decides the rendered state.

GhostDropdownMenuRadioGroup / GhostDropdownMenuRadioItem ​

PartProp / emitContract
Radio groupmodelValueControlled selected value (v-model).
Radio groupdefaultValueUncontrolled initial value.
Radio groupdisabledDisables all items when true.
Radio itemvalue (required)Value reported on selection.
Radio itemdisabledSkipped in roving.
Radio itememits selectEmits (value, event); closes unless event.preventDefault().

Structural parts ​

GhostDropdownMenuLabel, GhostDropdownMenuSeparator, and GhostDropdownMenuGroup accept as only (separator also decorative). They are not menu items and do not receive roving focus.

v-model contracts ​

  • GhostDropdownMenu: open + update:open (v-model:open).
  • GhostDropdownMenuCheckboxItem: checked + update:checked (v-model:checked), or modelValue + update:modelValue (v-model).
  • GhostDropdownMenuRadioGroup: modelValue + update:modelValue (v-model).

Events, slots, and exposed methods ​

  • Root default slot: { open: boolean, close: () => void }.
  • Parts expose { element: HTMLElement | null, focus(), blur() } where focusable.

State model ​

  • Binary open/closed on the root; content mounts with v-if="open".
  • data-state="open" | "closed" on trigger; data-state="open" on content while mounted.
  • data-placement on content from useFloating.
  • First-paint guard: visibility: hidden until isPositioned.
  • focusLastOnOpen flag set when opened via ArrowUp on the trigger.

Consumer data ​

The menu holds no domain collections. Checkbox and radio state are consumer-owned via v-model props; the primitives emit updates only.

Accessibility contract ​

WAI-ARIA APG Menu Button pattern (flat menu):

Semantics ​

  • Trigger: aria-haspopup="menu", aria-expanded, aria-controls, id, data-part="trigger".
  • Content: role="menu", tabindex="-1", id, data-part="content".
  • Items: role="menuitem" | menuitemcheckbox | menuitemradio", tabindex="-1", aria-disabled when disabled, aria-checked on checkbox/radio items.
  • Label: data-part="label" with deterministic id from useGhostId (not a menu item).
  • Separator: data-part="separator" via useGhostSeparator.

Keyboard interaction ​

KeyWhereBehavior
Enter / SpaceTriggerToggle open (non-anchor as).
ArrowDown / ArrowUpClosed triggerOpen; focus first / last item.
ArrowDown / ArrowUpOpen menuRoving focus among enabled items.
Home / EndOpen menuFirst / last enabled item.
Printable keyOpen menuTypeahead among item labels.
SpaceCheckbox itemToggle checked; menu stays open.
Enter / SpaceItem / radioActivate (radio closes menu).
EscapeOpen menuClose; restore focus to trigger.
Tab / Shift+TabOpen menuCloses the menu and moves focus to the next tab stop (no restore to trigger).

Disabled items are omitted from roving and typeahead. Single-character typeahead starts searching after the active item to cycle matches; extending a multi-character query starts at the active item so it stays focused while it still matches, with repeated-character fallback cycling when no item matches the repeated prefix.

Keys that belong to an active IME composition (isComposing, or the legacy keyCode 229 that WebKit reports for an IME-processed key after compositionend) are not menu commands: they do not run typeahead, move focus, activate items, or close the menu. This lives in useGhostMenuCollection and useDismissableLayer, so context menus and menubar menus share it.

Focus behavior ​

  • On open after positioned: focusFirstMenuItem or focusLastMenuItem on content.
  • On close (Escape, outside pointer without focusable target, item/radio select): restore focus to trigger via useFocusScope.
  • Outside pointer on another focusable control leaves focus on that control.

Rendering and customization ​

  • Root: renderless provider.
  • Content: class ghost-dropdown-menu-content, data-part="content". Consumer class and style merge with the library class and floating position styles.
  • Trigger / items / label / separator: data-part hooks as above; checkbox and radio use data-state where applicable.
  • Themed CSS under @layer ghostvue-theme uses --ghost-elevation-3-*, radius, spacing, interactive hover (--ghost-elevation-2-bg), focus ring tokens, and forced-colors overrides.

Environment behavior ​

SSR and hydration ​

  • useGhostId for SSR-safe IDs; closed menus render trigger only (v-if content).
  • Composables guard browser APIs in onMounted.
  • Integration: tests/integration/ssr-hydration.test.ts closed menu fixture.

Mobile and touch ​

  • useDismissableLayer capture-phase pointerdown for touch/mouse/pen.

Performance ​

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

Composition ​

  • useGhostDropdownMenu + overlay stack (same as GhostPopover for open/position/ dismiss).
  • useGhostMenuCollection for item queries and keyboard (shared with future menubar/submenu work).

Test plan ​

  • Unit (packages/vue/src/GhostDropdownMenu.test.ts): controlled/uncontrolled open; trigger aria-*; arrow open focusing first/last; roving, typeahead, Home/End; disabled skip; Escape/outside/select close; checkbox toggle without close; radio select closes; IME-owned keys (isComposing, keyCode 229) skip typeahead, roving, activation, and Escape.
  • SSR (packages/vue/src/overlay-ssr.test.ts, tests/integration/ssr-hydration.test.ts): closed and defaultOpen server render.
  • Theme CSS (tests/integration/ghost-dropdown-menu-theme-css.test.ts): token-only stylesheet.
  • E2E (tests/e2e/dropdown-menu.spec.ts): axe, open/close, menu ARIA, arrows, typeahead, Escape, item select, checkbox Space, radio select, outside click, disabled skip.
  • E2E (tests/e2e/ime-composition.spec.ts): WebKit-style keyCode 229 keys leave focus and open state unchanged; typeahead resumes afterwards.
  • Manual: Manual IME validation (automation cannot drive a real input method editor): with a Japanese, Chinese, or Korean IME on macOS Safari, macOS Chrome, Windows Chrome/Edge, and Firefox, compose text, move through candidates with the arrow keys, confirm with Enter, and cancel with Escape; the widget state must not change until the composition is committed, and the first keys after commit must behave normally.
  • Docs examples (tests/e2e/docs-examples.spec.ts): when wired to dropdown-menu/* ids.

Documentation plan ​

  • docs/components/dropdown-menu.md with headless and themed examples.
  • docs/components/dropdown-menu-spec.md (this document).
  • Sidebar and roadmap entries; manifests via pnpm manifests:write.

Compatibility and release impact ​

  • Additive minor Changeset for @ghostvue/vue and @ghostvue/themes.
  • Reuses existing overlay and menu-collection utilities (no breaking changes).

Open architectural questions ​

  • Submenu layering and aria-haspopup on items (GHO-92 / GHO-107).