Skip to content

GhostContextMenu ​

GhostContextMenu implements the WAI-ARIA APG context menu pattern for GHO-92: right-click, long-press, and Shift+F10 / ContextMenu keyboard shortcuts open a portaled role="menu" at the pointer via a virtual useFloating anchor.

Import the parts from @ghostvue/themes for the default elevated menu surface (the same item tokens as GhostDropdownMenu). To style the menu yourself, see Advanced: headless composition.

Act on a file ​

File actions

Right-click a file row or press Shift+F10 to duplicate, pin, open, or change row density, with each outcome announced.

Project files1 pinned
  • Q3 launch brief.md Pinned Markdown · 14 KB · Updated 2h ago
  • Token audit.csvSpreadsheet · 48 KB · Updated yesterday
  • Release checklist.mdMarkdown · 8 KB · Updated Nov 12
Right-click any file row or press Shift+F10 for actions.

Every part in this example comes from @ghostvue/themes. Right-click a file row, or press Tab to focus it and press Shift+F10 (or the ContextMenu key). The menu opens at the row with focus on its first item. Move to Duplicate with the arrow keys and press Enter: a copy appears below the file, the role="status" footer names it, and focus returns to the row that opened the menu. Pin to top toggles without closing the menu and updates the pinned badge. The themed GhostContextMenuContent sets data-themed so portaled panels receive elevation-3 tokens outside a .ghost-theme host.

GhostContextMenuTrigger renders a <span> from both @ghostvue/themes and @ghostvue/vue. It is a context target, not a menu button, so the theme adds no trigger styles; the row's own class gives it layout. Pass as to render another element, such as as="div" around a block of content.

Checkbox item model

GhostContextMenuCheckboxItem binds its state with v-model:checked or plain v-model. Both names stay in sync; if you bind both, checked decides what the item shows.

Nested commands ​

Choose Open with → Preview to act on the invoking file, or View → Row density → Compact to change the list. Enter, Space, and the forward arrow open a child. The back arrow and Escape return to its trigger. Escape at the root returns to the file row. Tab and Shift+Tab continue from that row even when a child is portaled. Forward is Right in LTR and Left in RTL.

Use GhostContextMenuItem, checkbox items, or radio items inside GhostSubmenuContent. The shared parts also support controlled open state and custom portal targets. Shared submenu API

Menus on list rows ​

When the rows are items of a composite widget whose items hold focus, such as GhostListbox, set focus-target="descendant" on the trigger. The trigger becomes a passive wrapper with no tab stop and no aria-haspopup. The menu opens for the option under the pointer, or for the focused option on Shift+F10 and the ContextMenu key, and focus returns to that option on close. A listbox selects the option first when it was not selected, so menu items act on the selection. If the action removes the option, focus moves to the list's next option. Keep every menu action available in a visible control outside the list as well. See the mail list.

vue
<GhostContextMenu>
  <GhostContextMenuTrigger as="div" focus-target="descendant">
    <GhostListbox v-model="selected" aria-label="Inbox">…</GhostListbox>
  </GhostContextMenuTrigger>
  <GhostContextMenuContent>…</GhostContextMenuContent>
</GhostContextMenu>

Advanced: headless composition ​

Teams that bring their own design system can import the same parts from @ghostvue/vue. They keep the menu behavior and paint nothing, so the example brings its own consumer CSS for the panel and item states.

Basic use ​

Basic Headless

Headless context menu on a row target with items, checkbox, radio group, label, separator, and disabled item.

Right-click this row for actions

Right-click or focus the target and press Shift+F10 to open. Item keyboard behavior comes from useGhostMenuCollection (shared with GhostDropdownMenu). The native contextmenu event is suppressed only when this menu actually opens.

API ​

See the generated component references for props, emits, slots, and styling hooks.

PropTypeDefaultDescription
defaultOpenbooleanfalseDeclared prop defaultOpen.
openboolean—Declared prop open.
SlotSlot propsDescription
defaultclose: () => void, open: booleanContainer content.

@ghostvue/themes adds no props, events, or slots to the headless GhostContextMenu API, which it forwards.

Specification ​

See GhostContextMenu specification and ADR 0011.