GhostContextMenu reference
Package: @ghostvue/vue. Status: experimental (stability policy).
Provides open state and a pointer anchor for a context menu with flat or nested file and item actions.
Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
defaultOpen | boolean | false | No | Declared prop `defaultOpen`. |
open | boolean | — | No | Declared prop `open`. |
Emits
None declared.
Models
| Prop | Event | Type | Description |
|---|---|---|---|
open | update:open | boolean | v-model binding for `open`. |
Slots
| Name | Description |
|---|---|
default | Container content. |
Slot props: default
| Name | Type | Description |
|---|---|---|
close | () => void | Slot prop `close`. |
open | boolean | Slot prop `open`. |
Exposed members
None declared.
Parts and data attributes
| Attribute | Value | Description |
|---|---|---|
data-part | root | Neutral content container. |
CSS variables
None declared.
Accessibility
Role: generic. APG pattern: https://www.w3.org/WAI/ARIA/apg/.
Required ARIA attributes: none.
Keyboard
None declared.
Verification
Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.
| Category | Status | Evidence |
|---|---|---|
| Automated keyboard | Not reviewed | No declared key is mapped to a browser test yet. |
| Manual interaction | Not reviewed | No review recorded. |
| Assistive technology | Not reviewed | No review recorded. |
Examples
context-menu/basic
Headless context menu on a row target with items, checkbox, radio group, label, separator, and disabled item.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostContextMenu,
GhostContextMenuCheckboxItem,
GhostContextMenuContent,
GhostContextMenuItem,
GhostContextMenuLabel,
GhostContextMenuRadioGroup,
GhostContextMenuRadioItem,
GhostContextMenuSeparator,
GhostContextMenuTrigger,
} from '@ghostvue/vue'
const showHidden = ref(false)
const sort = ref('name')
</script>
<template>
<GhostContextMenu>
<GhostContextMenuTrigger
data-testid="context-basic-trigger"
class="context-menu-e2e-target"
>
Right-click this row for actions
</GhostContextMenuTrigger>
<GhostContextMenuContent
class="row-actions-menu"
data-testid="context-basic-content"
:offset="4"
>
<GhostContextMenuLabel>Row actions</GhostContextMenuLabel>
<GhostContextMenuSeparator decorative />
<GhostContextMenuItem data-testid="context-basic-item-edit">
Edit
</GhostContextMenuItem>
<GhostContextMenuItem disabled data-testid="context-basic-item-disabled">
Archive (disabled)
</GhostContextMenuItem>
<GhostContextMenuSeparator decorative />
<GhostContextMenuCheckboxItem
v-model:checked="showHidden"
data-testid="context-checkbox-item"
>
Show hidden rows
</GhostContextMenuCheckboxItem>
<GhostContextMenuSeparator decorative />
<GhostContextMenuRadioGroup v-model="sort">
<GhostContextMenuRadioItem
value="name"
data-testid="context-radio-name"
>
Sort by name
</GhostContextMenuRadioItem>
<GhostContextMenuRadioItem
value="date"
data-testid="context-radio-date"
>
Sort by date
</GhostContextMenuRadioItem>
</GhostContextMenuRadioGroup>
</GhostContextMenuContent>
</GhostContextMenu>
</template>
<style scoped>
.context-menu-e2e-target {
display: block;
min-height: 12rem;
width: 100%;
}
</style>
<style>
/*
* Headless GhostContextMenu ships behavior and positioning only, so this
* sample brings its own consumer CSS. It is unscoped on purpose so the block
* can be copied into an app stylesheet as is, and the prefix keeps the
* classes from colliding with page styles.
*
* Colors read GhostVue semantic tokens when a theme is loaded and fall back
* to CSS system colors, which follow light and dark on their own. Items keep
* fixed geometry: highlight, hover, checked and disabled states only change
* color or a mark's visibility, so the menu never shifts. The highlight
* follows focus, which roves through the items. Nothing animates, so reduced
* motion needs no override.
*/
/* An opaque, layered panel above page content. */
.row-actions-menu {
background-color: var(--ghost-elevation-3-bg, Canvas);
border: 1px solid var(--ghost-elevation-3-border, GrayText);
border-radius: var(--ghost-radius-md, 0.375rem);
box-shadow: var(--ghost-elevation-3-shadow, 0 0.5rem 1.5rem rgb(0 0 0 / 20%));
box-sizing: border-box;
color: var(--ghost-surface-fg, CanvasText);
max-block-size: min(18rem, calc(100dvh - 2rem));
max-inline-size: calc(100vw - 2rem);
min-inline-size: 11rem;
overflow: auto;
padding: 0.25rem;
z-index: 50;
}
.row-actions-menu
:is([role='menuitem'], [role='menuitemcheckbox'], [role='menuitemradio']) {
border-radius: var(--ghost-radius-sm, 0.25rem);
cursor: default;
/* A transparent outline turns into a visible ring under forced colors. */
outline: 2px solid transparent;
outline-offset: -2px;
padding: 0.375rem 0.75rem 0.375rem 1.75rem;
position: relative;
}
/* Check mark slot, shown only on the checked row. */
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)::before {
block-size: 0.55rem;
border-block-end: 2px solid currentColor;
border-inline-end: 2px solid currentColor;
content: '';
inline-size: 0.3rem;
inset-block-start: 50%;
inset-inline-start: 0.7rem;
position: absolute;
transform: translateY(-65%) rotate(45deg);
visibility: hidden;
}
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-checked='true'] {
font-weight: 600;
}
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-checked='true']::before {
visibility: visible;
}
/* Radio rows show a dot instead of a check. */
.row-actions-menu [role='menuitemradio']::before {
block-size: 0;
border: 0.2rem solid currentColor;
border-radius: 50%;
inline-size: 0;
transform: translateY(-50%);
}
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
):hover:not(
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-disabled='true']
) {
background-color: var(--ghost-surface-muted-bg, Canvas);
}
/* Keyboard highlight. */
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
):focus {
background-color: var(--ghost-action-primary-bg, Highlight);
color: var(--ghost-action-primary-fg, HighlightText);
}
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-disabled='true'] {
color: var(--ghost-text-muted, GrayText);
cursor: not-allowed;
}
.row-actions-menu [data-part='label'] {
color: var(--ghost-text-muted, GrayText);
font-size: 0.8125rem;
padding: 0.375rem 0.75rem 0.25rem 1.75rem;
}
.row-actions-menu [data-part='separator'] {
border-block-start: 1px solid var(--ghost-border-default, GrayText);
margin-block: 0.25rem;
}
@media (forced-colors: active) {
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
):focus {
background-color: Highlight;
color: HighlightText;
forced-color-adjust: none;
}
.row-actions-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-disabled='true'] {
color: GrayText;
}
}
</style>
context-menu/themed
Right-click a file row or press Shift+F10 to duplicate, pin, open, or change row density, with each outcome announced.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostBadge,
GhostCard,
GhostContextMenu,
GhostContextMenuCheckboxItem,
GhostContextMenuContent,
GhostContextMenuItem,
GhostContextMenuLabel,
GhostContextMenuRadioGroup,
GhostContextMenuRadioItem,
GhostContextMenuSeparator,
GhostContextMenuTrigger,
GhostSubmenu,
GhostSubmenuContent,
GhostSubmenuTrigger,
} from '@ghostvue/themes'
interface ProjectFile {
id: string
name: string
kind: string
updated: string
pinned: boolean
}
const files = ref<ProjectFile[]>([
{
id: 'launch-brief',
name: 'Q3 launch brief.md',
kind: 'Markdown · 14 KB',
updated: 'Updated 2h ago',
pinned: true,
},
{
id: 'token-audit',
name: 'Token audit.csv',
kind: 'Spreadsheet · 48 KB',
updated: 'Updated yesterday',
pinned: false,
},
{
id: 'release-checklist',
name: 'Release checklist.md',
kind: 'Markdown · 8 KB',
updated: 'Updated Nov 12',
pinned: false,
},
])
const density = ref<'compact' | 'comfortable'>('comfortable')
const statusMessage = ref(
'Right-click any file row or press Shift+F10 for actions.',
)
function openFile(file: ProjectFile, app: string): void {
statusMessage.value = `Opened "${file.name}" in ${app}.`
}
// Name the copy after its source ("Token audit copy.csv", then "copy 2"),
// skipping names already in the list so every row stays distinct.
function copyName(name: string): string {
const dot = name.lastIndexOf('.')
const base = dot > 0 ? name.slice(0, dot) : name
const extension = dot > 0 ? name.slice(dot) : ''
const taken = new Set(files.value.map((file) => file.name))
let candidate = `${base} copy${extension}`
for (let count = 2; taken.has(candidate); count += 1) {
candidate = `${base} copy ${String(count)}${extension}`
}
return candidate
}
let copies = 0
// The copy lands right below its source. Focus still returns to the row that
// opened the menu, so the next Shift+F10 acts on the same file.
function duplicateFile(file: ProjectFile): void {
copies += 1
const copy: ProjectFile = {
...file,
id: `${file.id}-copy-${String(copies)}`,
name: copyName(file.name),
updated: 'Updated just now',
pinned: false,
}
files.value.splice(files.value.indexOf(file) + 1, 0, copy)
statusMessage.value = `Duplicated "${file.name}" as "${copy.name}".`
}
function setPinned(file: ProjectFile, pinned: boolean): void {
file.pinned = pinned
statusMessage.value = pinned
? `Pinned "${file.name}".`
: `Unpinned "${file.name}".`
}
function setDensity(value: string): void {
if (value === 'compact' || value === 'comfortable') {
density.value = value
statusMessage.value = `Row density set to ${value}.`
}
}
</script>
<template>
<GhostCard class="file-browser" :data-density="density">
<template #header>
<div class="file-browser__header">
<span class="file-browser__title">Project files</span>
<GhostBadge tone="neutral" variant="soft">
{{ files.filter((file) => file.pinned).length }} pinned
</GhostBadge>
</div>
</template>
<ul class="file-browser__list" aria-label="Project files">
<li v-for="file in files" :key="file.id" class="file-browser__item">
<GhostContextMenu>
<GhostContextMenuTrigger
class="file-browser__row"
data-testid="context-themed-trigger"
tabindex="0"
>
<span class="file-browser__name">
<span>{{ file.name }}</span>
<GhostBadge v-if="file.pinned" tone="accent" variant="soft">
Pinned
</GhostBadge>
</span>
<span class="file-browser__meta">
{{ file.kind }} · {{ file.updated }}
</span>
</GhostContextMenuTrigger>
<GhostContextMenuContent
:aria-label="`Actions for ${file.name}`"
data-testid="context-themed-content"
>
<GhostContextMenuLabel>{{ file.name }}</GhostContextMenuLabel>
<GhostContextMenuSeparator decorative />
<GhostSubmenu>
<GhostSubmenuTrigger>Open with</GhostSubmenuTrigger>
<GhostSubmenuContent>
<GhostContextMenuItem @select="openFile(file, 'Preview')">
Preview
</GhostContextMenuItem>
<GhostContextMenuItem @select="openFile(file, 'Editor')">
Editor
</GhostContextMenuItem>
</GhostSubmenuContent>
</GhostSubmenu>
<GhostContextMenuItem @select="duplicateFile(file)">
<span class="context-menu__indicator" aria-hidden="true" />
Duplicate
</GhostContextMenuItem>
<GhostContextMenuSeparator decorative />
<GhostContextMenuCheckboxItem
:checked="file.pinned"
@update:checked="setPinned(file, $event)"
>
<span class="context-menu__indicator" aria-hidden="true">
{{ file.pinned ? '✓' : '' }}
</span>
Pin to top
</GhostContextMenuCheckboxItem>
<GhostContextMenuSeparator decorative />
<GhostSubmenu>
<GhostSubmenuTrigger>View</GhostSubmenuTrigger>
<GhostSubmenuContent portal>
<GhostSubmenu>
<GhostSubmenuTrigger>Row density</GhostSubmenuTrigger>
<GhostSubmenuContent>
<GhostContextMenuRadioGroup
:model-value="density"
@update:model-value="setDensity"
>
<GhostContextMenuRadioItem value="compact">
<span
class="context-menu__indicator"
aria-hidden="true"
>
{{ density === 'compact' ? '●' : '' }}
</span>
Compact
</GhostContextMenuRadioItem>
<GhostContextMenuRadioItem value="comfortable">
<span
class="context-menu__indicator"
aria-hidden="true"
>
{{ density === 'comfortable' ? '●' : '' }}
</span>
Comfortable
</GhostContextMenuRadioItem>
</GhostContextMenuRadioGroup>
</GhostSubmenuContent>
</GhostSubmenu>
</GhostSubmenuContent>
</GhostSubmenu>
</GhostContextMenuContent>
</GhostContextMenu>
</li>
</ul>
<template #footer>
<div class="file-browser__status" role="status" aria-live="polite">
{{ statusMessage }}
</div>
</template>
</GhostCard>
</template>
<style scoped>
.file-browser {
inline-size: 100%;
max-inline-size: 34rem;
}
.file-browser__header {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
justify-content: space-between;
}
.file-browser__title {
color: var(--ghost-surface-fg);
font-size: var(--ghost-type-size-md);
font-weight: var(--ghost-type-weight-semibold);
}
.file-browser__list {
display: grid;
gap: var(--ghost-space-gap-xs);
list-style: none;
margin: 0;
padding: 0;
}
.file-browser__item {
margin: 0;
}
.file-browser__row {
align-items: center;
background-color: var(--ghost-surface-subtle-bg);
border: var(--ghost-border-hairline-width) solid var(--ghost-border-subtle);
border-radius: var(--ghost-radius-md);
color: var(--ghost-surface-fg);
cursor: context-menu;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-xs) var(--ghost-space-gap-md);
justify-content: space-between;
padding: var(--ghost-space-inset-sm) var(--ghost-space-inset-md);
}
.file-browser[data-density='compact'] .file-browser__row {
padding: var(--ghost-space-inset-xs) var(--ghost-space-inset-sm);
}
.file-browser__row:hover {
background-color: var(--ghost-elevation-2-bg);
}
.file-browser__row:focus-visible {
outline: var(--ghost-focus-ring-width) solid var(--ghost-focus-ring-color);
outline-offset: var(--ghost-focus-ring-offset);
}
.file-browser__name {
align-items: center;
display: inline-flex;
flex-wrap: wrap;
font-size: var(--ghost-type-size-sm);
font-weight: var(--ghost-type-weight-medium);
gap: var(--ghost-space-gap-xs);
}
.file-browser__meta {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
}
.file-browser__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
}
.context-menu__indicator {
display: inline-block;
inline-size: 1em;
text-align: center;
}
</style>