GhostMenubar
GhostMenubar implements the WAI-ARIA APG Menubar pattern (GHO-107): a horizontal role="menubar" with one tab stop, roving focus among top-level menuitem triggers, and action menus that can contain nested commands.
Import the parts from @ghostvue/themes for default elevation and item styling. To style the bar and menus yourself, see Advanced: headless composition.
Run editor commands
Create, duplicate, or export a document from a File, Edit, and View menubar; the document name and status line show each command.
<script setup lang="ts">
import { computed, ref } from 'vue'
import {
GhostButton,
GhostCard,
GhostMenubar,
GhostMenubarCheckboxItem,
GhostMenubarContent,
GhostMenubarItem,
GhostMenubarLabel,
GhostMenubarMenu,
GhostMenubarRadioGroup,
GhostMenubarRadioItem,
GhostMenubarSeparator,
GhostMenubarTrigger,
GhostSubmenu,
GhostSubmenuContent,
GhostSubmenuTrigger,
} from '@ghostvue/themes'
type LayoutMode = 'comfortable' | 'compact'
const wordWrap = ref(true)
const lineNumbers = ref(true)
const layout = ref<LayoutMode>('comfortable')
const documentName = ref('release-notes.md')
const lastAction = ref('Ready')
const statusSummary = computed(() => {
const flags = [
wordWrap.value ? 'Word wrap on' : 'Word wrap off',
lineNumbers.value ? 'Line numbers on' : 'Line numbers off',
layout.value === 'comfortable' ? 'Comfortable layout' : 'Compact layout',
].join(' · ')
return `${lastAction.value} — ${flags}`
})
function runAction(label: string): void {
lastAction.value = label
}
// File commands change the open document, so the result shows in the editor
// body as well as in the status line. Focus returns to the File trigger.
function newDraft(): void {
documentName.value = 'Untitled draft.md'
runAction('Created new draft')
}
function duplicateDocument(): void {
const source = documentName.value
documentName.value = source.replace(/(\.md)?$/, ' copy.md')
runAction(`Duplicated ${source}`)
}
function setLayout(value: string): void {
if (value === 'comfortable' || value === 'compact') {
layout.value = value
lastAction.value = `Layout: ${value}`
}
}
</script>
<template>
<GhostCard class="editor-shell">
<template #header>
<div class="editor-shell__bar">
<GhostMenubar class="editor-menubar" aria-label="Document actions">
<GhostMenubarMenu>
<GhostMenubarTrigger :as="GhostButton" variant="ghost" size="sm">
File
</GhostMenubarTrigger>
<GhostMenubarContent aria-label="File" :offset="6">
<GhostMenubarItem @select="newDraft">
<span class="menubar__indicator" aria-hidden="true" />
New draft
</GhostMenubarItem>
<GhostMenubarItem @select="duplicateDocument">
<span class="menubar__indicator" aria-hidden="true" />
Duplicate
</GhostMenubarItem>
<GhostMenubarSeparator decorative />
<GhostSubmenu>
<GhostSubmenuTrigger>Export</GhostSubmenuTrigger>
<GhostSubmenuContent>
<GhostMenubarItem @select="runAction('Exported PDF')">
PDF
</GhostMenubarItem>
<GhostSubmenu>
<GhostSubmenuTrigger>Text formats</GhostSubmenuTrigger>
<GhostSubmenuContent portal>
<GhostMenubarItem
@select="runAction('Exported Markdown')"
>
Markdown
</GhostMenubarItem>
<GhostMenubarItem
@select="runAction('Exported plain text')"
>
Plain text
</GhostMenubarItem>
</GhostSubmenuContent>
</GhostSubmenu>
</GhostSubmenuContent>
</GhostSubmenu>
<GhostMenubarItem disabled>
<span class="menubar__indicator" aria-hidden="true" />
Publish (read-only)
</GhostMenubarItem>
</GhostMenubarContent>
</GhostMenubarMenu>
<GhostMenubarMenu>
<GhostMenubarTrigger :as="GhostButton" variant="ghost" size="sm">
Edit
</GhostMenubarTrigger>
<GhostMenubarContent aria-label="Edit" :offset="6">
<GhostMenubarItem @select="runAction('Undid last change')">
<span class="menubar__indicator" aria-hidden="true" />
Undo
</GhostMenubarItem>
<GhostMenubarItem @select="runAction('Redid change')">
<span class="menubar__indicator" aria-hidden="true" />
Redo
</GhostMenubarItem>
<GhostMenubarSeparator decorative />
<GhostMenubarItem @select="runAction('Opened find & replace')">
<span class="menubar__indicator" aria-hidden="true" />
Find & replace
</GhostMenubarItem>
</GhostMenubarContent>
</GhostMenubarMenu>
<GhostMenubarMenu>
<GhostMenubarTrigger :as="GhostButton" variant="ghost" size="sm">
View
</GhostMenubarTrigger>
<GhostMenubarContent aria-label="View" :offset="6">
<GhostMenubarLabel>Editor</GhostMenubarLabel>
<GhostMenubarCheckboxItem v-model:checked="wordWrap">
<span class="menubar__indicator" aria-hidden="true">
{{ wordWrap ? '✓' : '' }}
</span>
Word wrap
</GhostMenubarCheckboxItem>
<GhostMenubarCheckboxItem v-model:checked="lineNumbers">
<span class="menubar__indicator" aria-hidden="true">
{{ lineNumbers ? '✓' : '' }}
</span>
Line numbers
</GhostMenubarCheckboxItem>
<GhostMenubarSeparator decorative />
<GhostMenubarLabel>Density</GhostMenubarLabel>
<GhostMenubarRadioGroup
:model-value="layout"
@update:model-value="setLayout"
>
<GhostMenubarRadioItem value="comfortable">
<span class="menubar__indicator" aria-hidden="true">
{{ layout === 'comfortable' ? '●' : '' }}
</span>
Comfortable
</GhostMenubarRadioItem>
<GhostMenubarRadioItem value="compact">
<span class="menubar__indicator" aria-hidden="true">
{{ layout === 'compact' ? '●' : '' }}
</span>
Compact
</GhostMenubarRadioItem>
</GhostMenubarRadioGroup>
</GhostMenubarContent>
</GhostMenubarMenu>
</GhostMenubar>
</div>
</template>
<div class="editor-shell__body">
<span class="editor-shell__doc">{{ documentName }}</span>
<span class="editor-shell__hint">
Use ArrowLeft / ArrowRight across menus, ArrowDown to open.
</span>
</div>
<template #footer>
<div class="editor-shell__status" role="status" aria-live="polite">
{{ statusSummary }}
</div>
</template>
</GhostCard>
</template>
<style scoped>
.editor-shell {
inline-size: 100%;
max-inline-size: 32rem;
}
.editor-shell__bar {
display: flex;
flex-wrap: wrap;
}
.editor-menubar {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-xs);
}
.editor-shell__body {
display: grid;
gap: var(--ghost-space-gap-xs);
}
.editor-shell__doc {
color: var(--ghost-surface-fg);
font-size: var(--ghost-type-size-sm);
font-weight: var(--ghost-type-weight-semibold);
}
.editor-shell__hint,
.editor-shell__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
}
.menubar__indicator {
display: inline-block;
inline-size: 1em;
text-align: center;
}
</style>
Every part in this example comes from @ghostvue/themes. The editor toolbar composes GhostMenubarTrigger with :as="GhostButton" and keeps a single Tab stop across File, Edit, and View. Press Tab to reach File, then ArrowDown, Enter, or Space to open it with focus on New draft. Press Enter to run it: the document name changes to Untitled draft.md, the role="status" footer records the command, and focus returns to File. Duplicate names a copy of the open document in the same way. Checkbox and radio items under View toggle without leaving the menu. Themed content sets data-themed on portaled panels so .ghost-menubar-content picks up elevation-3 tokens and item hover and focus styles in light and dark mode.
Checkbox item model
GhostMenubarCheckboxItem 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
Open File → Export → Text formats → Markdown to export the document. The forward arrow on Export opens its child. The same arrow on PDF switches to Edit and focuses its first command. Back closes the current child, or switches to the previous top-level menu from root content. Forward is Right in LTR and Left in RTL. Escape returns one level at a time, and Tab or Shift+Tab leaves the entire menubar from any depth.
Advanced: headless composition
Teams that bring their own design system can import the same parts from @ghostvue/vue. They keep the menubar behavior and paint nothing, so the example brings its own consumer CSS for the bar, panels, and item states.
Basic use
Headless menubar with items, checkbox, radio group, label, separator, and disabled item.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostMenubar,
GhostMenubarCheckboxItem,
GhostMenubarContent,
GhostMenubarItem,
GhostMenubarLabel,
GhostMenubarMenu,
GhostMenubarRadioGroup,
GhostMenubarRadioItem,
GhostMenubarSeparator,
GhostMenubarTrigger,
} from '@ghostvue/vue'
const showHidden = ref(false)
const sort = ref('name')
</script>
<template>
<GhostMenubar>
<GhostMenubarMenu>
<GhostMenubarTrigger>File</GhostMenubarTrigger>
<GhostMenubarContent class="app-menubar-menu" :offset="8">
<GhostMenubarLabel>File</GhostMenubarLabel>
<GhostMenubarSeparator decorative />
<GhostMenubarItem>New</GhostMenubarItem>
<GhostMenubarItem disabled>Archive (disabled)</GhostMenubarItem>
</GhostMenubarContent>
</GhostMenubarMenu>
<GhostMenubarMenu>
<GhostMenubarTrigger>Edit</GhostMenubarTrigger>
<GhostMenubarContent class="app-menubar-menu" :offset="8">
<GhostMenubarCheckboxItem v-model:checked="showHidden">
Show hidden files
</GhostMenubarCheckboxItem>
<GhostMenubarSeparator decorative />
<GhostMenubarRadioGroup v-model="sort">
<GhostMenubarRadioItem value="name"
>Sort by name</GhostMenubarRadioItem
>
<GhostMenubarRadioItem value="date"
>Sort by date</GhostMenubarRadioItem
>
</GhostMenubarRadioGroup>
</GhostMenubarContent>
</GhostMenubarMenu>
</GhostMenubar>
</template>
<style>
/*
* Headless GhostMenubar 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. */
.app-menubar-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;
}
.app-menubar-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. */
.app-menubar-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;
}
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-checked='true'] {
font-weight: 600;
}
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-checked='true']::before {
visibility: visible;
}
/* Radio rows show a dot instead of a check. */
.app-menubar-menu [role='menuitemradio']::before {
block-size: 0;
border: 0.2rem solid currentColor;
border-radius: 50%;
inline-size: 0;
transform: translateY(-50%);
}
.app-menubar-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. */
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
):focus {
background-color: var(--ghost-action-primary-bg, Highlight);
color: var(--ghost-action-primary-fg, HighlightText);
}
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-disabled='true'] {
color: var(--ghost-text-muted, GrayText);
cursor: not-allowed;
}
.app-menubar-menu [data-part='label'] {
color: var(--ghost-text-muted, GrayText);
font-size: 0.8125rem;
padding: 0.375rem 0.75rem 0.25rem 1.75rem;
}
.app-menubar-menu [data-part='separator'] {
border-block-start: 1px solid var(--ghost-border-default, GrayText);
margin-block: 0.25rem;
}
@media (forced-colors: active) {
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
):focus {
background-color: Highlight;
color: HighlightText;
forced-color-adjust: none;
}
.app-menubar-menu
:is(
[role='menuitem'],
[role='menuitemcheckbox'],
[role='menuitemradio']
)[aria-disabled='true'] {
color: GrayText;
}
}
</style>
GhostMenubar registers each GhostMenubarMenu, enforces at most one open menu, and delegates horizontal trigger navigation to useRovingFocus. Each menu reuses useGhostMenubarMenu (overlay stack + useGhostMenuCollection for item keyboard behavior).
API
See the generated component references for props, emits, slots, exposed members, styling hooks, and executable examples.
| Prop | Type | Default | Description |
|---|---|---|---|
as | Component | string | "div" | Declared prop as. |
dir | 'ltr' | 'rtl' | — | Declared prop dir. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Container content. |
@ghostvue/themes adds no props, events, or slots to the headless GhostMenubar API, which it forwards.
Composition
GhostMenubar—role="menubar"container; optionaldirfor RTL arrow flip.GhostMenubarMenu— renderless open state (v-model:open).GhostMenubarTrigger—role="menuitem"witharia-haspopup="menu".GhostMenubarContent— floatingrole="menu"(defaultplacement="bottom-start").- Item, group, label, separator, checkbox, and radio parts match
GhostDropdownMenusemantics inside each menu.
Place GhostSubmenu in the menu content and use the usual GhostMenubarItem, checkbox, and radio parts for its commands. Shared submenu API
See GhostMenubar specification for the full accessibility contract and keyboard table.