Document toolbarNo formatting action applied yet
GhostToolbar
GhostToolbar groups related controls into a single role="toolbar" container with roving tabindex and arrow-key movement. Import it from @ghostvue/vue for headless use, or from @ghostvue/themes for a default flex layout.
Document formatting toolbar
Document formatting toolbar
Themed toolbar with grouped formatting controls, vertical separator, and roving focus.
editor-actions.vue
vue
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostCard,
GhostSeparator,
GhostToolbar,
} from '@ghostvue/themes'
const lastAction = ref('No formatting action applied yet')
function runAction(name: string): void {
lastAction.value = `Applied: ${name}`
}
</script>
<template>
<div class="toolbar-showcase">
<GhostCard>
<template #header>
<div class="toolbar-showcase__header">
<span class="toolbar-showcase__title">Document toolbar</span>
<span class="toolbar-showcase__status" role="status">
{{ lastAction }}
</span>
</div>
</template>
<GhostToolbar label="Document formatting" class="toolbar-showcase__bar">
<GhostButton
size="sm"
variant="outline"
tone="neutral"
@click="runAction('Bold')"
>
Bold
</GhostButton>
<GhostButton
size="sm"
variant="outline"
tone="neutral"
@click="runAction('Italic')"
>
Italic
</GhostButton>
<GhostButton
size="sm"
variant="outline"
tone="neutral"
@click="runAction('Code')"
>
Code
</GhostButton>
<GhostSeparator orientation="vertical" />
<GhostButton
size="sm"
variant="ghost"
tone="neutral"
@click="runAction('Insert link')"
>
Link
</GhostButton>
<GhostButton
size="sm"
variant="ghost"
tone="danger"
@click="runAction('Clear formatting')"
>
Clear
</GhostButton>
</GhostToolbar>
</GhostCard>
</div>
</template>
<style scoped>
.toolbar-showcase {
display: grid;
}
.toolbar-showcase__header {
display: grid;
gap: var(--ghost-space-gap-2xs);
}
.toolbar-showcase__title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-md);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-snug);
}
.toolbar-showcase__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
line-height: var(--ghost-type-line-normal);
}
.toolbar-showcase__bar {
flex-wrap: wrap;
}
@container ghost-demo (min-width: 28rem) {
.toolbar-showcase__header {
align-items: baseline;
grid-template-columns: auto minmax(0, 1fr);
justify-content: space-between;
}
.toolbar-showcase__status {
text-align: end;
}
}
</style>
A single Tab stop enters the GhostToolbar and arrow keys move focus across formatting and clear actions, separated by a semantic vertical GhostSeparator.
API
| Prop | Type | Default | Description |
|---|---|---|---|
as | GhostToolbarElement | "div" | Root element tag for the toolbar container. |
dir | GhostToolbarDirection | — | Optional text direction for horizontal arrow reversal in RTL. |
label | string | — | Accessible name via aria-label when a visible label element is not used. |
loop | boolean | true | Wrap arrow and Home/End movement from last enabled item to first. |
orientation | GhostToolbarOrientation | "horizontal" | Toolbar layout and roving arrow axis. Sets aria-orientation when vertical. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Toolbar items such as GhostButton, GhostSwitch, and GhostSeparator. |
@ghostvue/themes adds no props, events, or slots to the headless GhostToolbar API, which it forwards.
Native attributes and listeners fall through to the root. There is no v-model. defineExpose provides element, focus(), and blur() on the toolbar root.
Vertical layout
Themed
Flex layout from @ghostvue/themes.
No annotation added
themed.vue
vue
<script setup lang="ts">
import { ref } from 'vue'
import { GhostButton, GhostSeparator, GhostToolbar } from '@ghostvue/themes'
const action = ref('No annotation added')
</script>
<template>
<div class="toolbar-themed-example">
<GhostToolbar label="Annotation tools" orientation="vertical">
<GhostButton size="sm" @click="action = 'Added a text annotation'">
Text
</GhostButton>
<GhostButton size="sm" @click="action = 'Added a highlight'">
Highlight
</GhostButton>
<GhostSeparator orientation="horizontal" :decorative="false" />
<GhostButton
size="sm"
variant="outline"
@click="action = 'No annotation added'"
>
Clear
</GhostButton>
</GhostToolbar>
<p role="status">{{ action }}</p>
</div>
</template>
<style scoped>
.toolbar-themed-example {
display: grid;
justify-items: start;
gap: var(--ghost-space-gap-sm);
}
</style>
Use orientation="vertical" for a column of tools. In the annotation example, ArrowDown focuses Highlight and Enter applies it. Clear belongs to a separate group and the horizontal separator is skipped by arrow keys.
Separators
Use a vertical separator in a horizontal toolbar and a horizontal separator in a vertical toolbar. Set :decorative="false" when the separator marks a meaningful grouping, as in the document formatting and annotation examples.
Themed use
The themed wrapper adds flex row/column layout under .ghost-theme or .ghost-themed-scope. See the default theme guide.
Advanced: headless composition
Basic use
Basic Headless
Horizontal action bar with roving focus among buttons.
basic.vue
vue
<script setup lang="ts">
import { GhostButton, GhostToolbar } from '@ghostvue/vue'
</script>
<template>
<GhostToolbar label="Row actions" data-testid="example-toolbar-basic">
<GhostButton type="button">Edit</GhostButton>
<GhostButton type="button">Share</GhostButton>
<GhostButton type="button" disabled>Archive</GhostButton>
</GhostToolbar>
</template>
The default slot accepts focusable controls such as GhostButton and GhostSwitch. Arrow keys skip disabled items. The following examples show a custom vertical layout and separators with consumer CSS.
Vertical Headless
Vertical toolbar with up and down arrow movement.
vertical.vue
vue
<script setup lang="ts">
import { GhostButton, GhostToolbar } from '@ghostvue/vue'
</script>
<template>
<GhostToolbar orientation="vertical" label="Annotation tools">
<GhostButton type="button">Pointer</GhostButton>
<GhostButton type="button">Text</GhostButton>
<GhostButton type="button">Shape</GhostButton>
</GhostToolbar>
</template>
Separators Headless
Group controls with semantic vertical separators.
separators.vue
vue
<script setup lang="ts">
import { GhostButton, GhostSeparator, GhostToolbar } from '@ghostvue/vue'
</script>
<template>
<GhostToolbar class="clipboard" label="Clipboard">
<GhostButton type="button">Cut</GhostButton>
<GhostButton type="button">Copy</GhostButton>
<GhostButton type="button">Paste</GhostButton>
<GhostSeparator orientation="vertical" />
<GhostButton type="button">Undo</GhostButton>
<GhostButton type="button">Redo</GhostButton>
</GhostToolbar>
</template>
<style scoped>
/*
* Headless path ships no layout or visuals; this is consumer CSS for the
* sample. A row keeps the vertical separator between the button groups.
*/
.clipboard {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.ghost-separator {
align-self: stretch;
border-inline-start: 1px solid GrayText;
}
</style>
To attach the same roving focus behavior to a native host, pass a template ref as element to the composable.
Composable Headless
Same contract as GhostToolbar on a native host.
composable.vue
vue
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import { GhostButton, useGhostToolbar } from '@ghostvue/vue'
const root = useTemplateRef<HTMLElement>('root')
const { rootProps } = useGhostToolbar({
element: root,
orientation: 'horizontal',
label: 'Filters',
})
</script>
<template>
<div ref="root" v-bind="rootProps" data-testid="toolbar-composable">
<GhostButton type="button">All</GhostButton>
<GhostButton type="button">Open</GhostButton>
<GhostButton type="button">Closed</GhostButton>
</div>
</template>
Styling
The unstyled root uses class ghost-toolbar, data-part="root", data-ghost-toolbar, and data-orientation. Recipe CSS targets flex direction from data-orientation.
Accessibility
Follow the WAI-ARIA APG Toolbar pattern. Name the bar with label or aria-labelledby. Tab enters the group at the current roving item; arrow keys move among enabled controls; Tab moves focus out of the group.