Announcement draft
Combine single-select alignment with multi-select text formatting.
Scheduled maintenance completes Sunday at 04:00 UTC with zero expected downtime for read replicas.
Alignment: left · Formatting: bold
GhostToggleGroup groups toggle buttons that share aria-pressed state for single-choice or multi-choice toolbars—table density pickers, layout switches, and formatting controls. It is not a radio group: a pressed item in single mode can be toggled off. Keyboard arrow keys rove among items via useRovingFocus; selection uses useControllableState.
See the specification for the accessibility contract.
Single-select alignment and multi-select formatting with GhostToggleGroup.
Combine single-select alignment with multi-select text formatting.
Scheduled maintenance completes Sunday at 04:00 UTC with zero expected downtime for read replicas.
Alignment: left · Formatting: bold
<script setup lang="ts">
import { computed, ref } from 'vue'
import {
GhostCard,
GhostToggleGroup,
GhostToggleGroupItem,
} from '@ghostvue/themes'
const alignment = ref<'left' | 'center' | 'right'>('left')
const formats = ref<string[]>(['bold'])
const previewStyle = computed(() => ({
textAlign: alignment.value,
fontWeight: formats.value.includes('bold') ? '700' : '400',
fontStyle: formats.value.includes('italic') ? 'italic' : 'normal',
textDecoration: formats.value.includes('underline') ? 'underline' : 'none',
}))
</script>
<template>
<section class="editor" aria-labelledby="editor-title">
<GhostCard>
<template #header>
<div class="editor__header">
<h2 id="editor-title" class="editor__title">Announcement draft</h2>
<p class="editor__lead">
Combine single-select alignment with multi-select text formatting.
</p>
</div>
</template>
<div class="editor__body">
<div class="editor__toolbar" role="toolbar" aria-label="Formatting">
<GhostToggleGroup
v-model="formats"
type="multiple"
aria-label="Text formatting"
>
<GhostToggleGroupItem value="bold" aria-label="Bold">
B
</GhostToggleGroupItem>
<GhostToggleGroupItem value="italic" aria-label="Italic">
I
</GhostToggleGroupItem>
<GhostToggleGroupItem value="underline" aria-label="Underline">
U
</GhostToggleGroupItem>
</GhostToggleGroup>
<GhostToggleGroup
v-model="alignment"
type="single"
aria-label="Text alignment"
>
<GhostToggleGroupItem value="left">Left</GhostToggleGroupItem>
<GhostToggleGroupItem value="center">Center</GhostToggleGroupItem>
<GhostToggleGroupItem value="right">Right</GhostToggleGroupItem>
</GhostToggleGroup>
</div>
<p class="editor__preview" :style="previewStyle">
Scheduled maintenance completes Sunday at 04:00 UTC with zero expected
downtime for read replicas.
</p>
</div>
<template #footer>
<p class="editor__status" role="status">
Alignment: {{ alignment }} · Formatting:
{{ formats.length > 0 ? formats.join(', ') : 'none' }}
</p>
</template>
</GhostCard>
</section>
</template>
<style scoped>
.editor {
max-inline-size: 36rem;
}
.editor__header {
display: grid;
gap: var(--ghost-space-gap-xs);
padding-block-end: var(--ghost-space-stack-sm);
}
.editor__title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
}
.editor__lead,
.editor__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
overflow-wrap: anywhere;
}
.editor__body {
display: grid;
gap: var(--ghost-space-stack-md);
}
.editor__toolbar {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
}
.editor__preview {
border: var(--ghost-border-hairline-width) solid var(--ghost-border-muted);
border-radius: var(--ghost-radius-md);
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-md);
line-height: var(--ghost-type-line-normal);
margin: 0;
padding: var(--ghost-space-inset-md);
}
</style>
The announcement composer pairs a multiple formatting GhostToggleGroup with a single alignment GhostToggleGroup, updating the live preview text.
Use the composer's Text alignment group when only one option can be active. Press the selected option again to clear it. The preview aligns to the start when the group has no selection.
Use the Text formatting group when choices can coexist. Move focus from Bold to Italic with ArrowRight. Press Space to toggle the focused format while preserving the other active formats.
Segmented layout switcher with default styles.
<script setup lang="ts">
import { GhostToggleGroup, GhostToggleGroupItem } from '@ghostvue/themes'
</script>
<template>
<GhostToggleGroup default-value="list" aria-label="Asset layout">
<GhostToggleGroupItem value="list">List</GhostToggleGroupItem>
<GhostToggleGroupItem value="grid">Grid</GhostToggleGroupItem>
<GhostToggleGroupItem value="board">Board</GhostToggleGroupItem>
</GhostToggleGroup>
</template>
Small toggle group in a reply bar beside a small input and button.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostInput,
GhostToggleGroup,
GhostToggleGroupItem,
} from '@ghostvue/themes'
const formats = ref<string[]>(['bold'])
const reply = ref('')
</script>
<template>
<!--
A compact reply bar: the toggle group, input and button all take
size="sm", so the row keeps one height.
-->
<div class="reply-bar">
<GhostToggleGroup
v-model="formats"
type="multiple"
size="sm"
aria-label="Reply formatting"
>
<GhostToggleGroupItem value="bold">Bold</GhostToggleGroupItem>
<GhostToggleGroupItem value="italic">Italic</GhostToggleGroupItem>
<GhostToggleGroupItem value="code">Code</GhostToggleGroupItem>
</GhostToggleGroup>
<GhostInput
v-model="reply"
size="sm"
aria-label="Reply"
placeholder="Write a reply"
/>
<GhostButton size="sm">Send</GhostButton>
</div>
</template>
<style scoped>
.reply-bar {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
}
</style>
Set size to sm, md (the default) or lg on the themed root to match a GhostButton or GhostInput of the same size. The track takes its height from control.size.<size>, its label size and item padding follow, and every item uses the root size. Each density changes those tokens, and on touch screens every size keeps a 44px item.
<script setup lang="ts">
import { ref } from 'vue'
import { GhostToggleGroup, GhostToggleGroupItem } from '@ghostvue/themes'
const layout = ref('list')
</script>
<template>
<GhostToggleGroup v-model="layout" aria-label="Layout">
<GhostToggleGroupItem value="list">List</GhostToggleGroupItem>
<GhostToggleGroupItem value="grid">Grid</GhostToggleGroupItem>
</GhostToggleGroup>
</template>Label the group with aria-label or aria-labelledby. Each item is named by its slot content or aria-label.
Use the parts from @ghostvue/vue when your application supplies the layout and pressed styles. These previews keep the same single and multiple selection behavior.
Exclusive aria-pressed density controls.
<script setup lang="ts">
import { ref } from 'vue'
import { GhostToggleGroup, GhostToggleGroupItem } from '@ghostvue/vue'
const density = ref('comfortable')
</script>
<template>
<GhostToggleGroup v-model="density" aria-label="Row density">
<GhostToggleGroupItem value="compact">Compact</GhostToggleGroupItem>
<GhostToggleGroupItem value="comfortable">Comfortable</GhostToggleGroupItem>
<GhostToggleGroupItem value="spacious">Spacious</GhostToggleGroupItem>
</GhostToggleGroup>
</template>
Independent formatting toggles in one group.
<script setup lang="ts">
import { ref } from 'vue'
import { GhostToggleGroup, GhostToggleGroupItem } from '@ghostvue/vue'
const formats = ref<string[]>(['bold'])
</script>
<template>
<GhostToggleGroup
v-model="formats"
type="multiple"
aria-label="Text formatting"
>
<GhostToggleGroupItem value="bold">Bold</GhostToggleGroupItem>
<GhostToggleGroupItem value="italic">Italic</GhostToggleGroupItem>
<GhostToggleGroupItem value="underline">Underline</GhostToggleGroupItem>
</GhostToggleGroup>
</template>
GhostToggleGroup | Prop | Type | Default | Description |
|---|---|---|---|
as | GhostToggleGroupElement | "div" | Root host element. |
defaultValue | GhostToggleGroupValue | — | Initial selection when modelValue is omitted. |
dir | 'ltr' | 'rtl' | — | Explicit text direction for horizontal roving. |
disabled | boolean | false | Disables every item. |
modelValue | GhostToggleGroupValue | — | Controlled selection; shape follows type. |
orientation | 'horizontal' | 'vertical' | "horizontal" | Arrow-key roving layout. |
type | 'multiple' | 'single' | "single" | Single vs multiple pressed items. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Toggle group items. |
@ghostvue/themes adds these to the headless GhostToggleGroup API, which it forwards:
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | "md" | Track height, label size, and item padding from control.size.<size>, matching a GhostButton or GhostInput of the same size. Items take the root size. The default omits data-size so CSS can treat a missing hook as md. |
Emits: update:modelValue with string, string[], or undefined.
Exposed: { element, focus(), blur() }.
GhostToggleGroupItem | Prop | Type | Default | Description |
|---|---|---|---|
as | GhostToggleGroupItemElement | "button" | Tag name or component for the toggle control. |
disabled | boolean | false | Disables toggling and roving focus for this item. |
value | string | Required | Stable value for this item in the group model. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Primary content. |
Exposed: { element, focus(), blur() }.
ghost-toggle-group, ghost-toggle-group-itemdata-ghost-toggle-group, data-ghost-toggle-group-value, data-part, data-state (on / off)Themed styles ship from @ghostvue/themes (GhostToggleGroup, GhostToggleGroupItem).
role="group" with an accessible name.button (default) with aria-pressed="true" | "false".Home / End jump to ends.Do not use radiogroup semantics for exclusive layout pickers when deselection should be allowed; use GhostRadioGroup when a permanent single choice is required.