Skip to content

GhostToggleGroup ​

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.

Announcement draft

Single-select alignment and multi-select formatting with GhostToggleGroup.

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

The announcement composer pairs a multiple formatting GhostToggleGroup with a single alignment GhostToggleGroup, updating the live preview text.

Examples ​

Single selection ​

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.

Multiple 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.

Themed segmented control ​

Toggle group themed

Segmented layout switcher with default styles.

Size ​

Size

Small toggle group in a reply bar beside a small input and button.

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.

Usage ​

vue
<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.

Advanced: headless composition ​

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.

Toggle group single Headless

Exclusive aria-pressed density controls.

Toggle group multiple Headless

Independent formatting toggles in one group.

API ​

GhostToggleGroup ​

PropTypeDefaultDescription
asGhostToggleGroupElement"div"Root host element.
defaultValueGhostToggleGroupValue—Initial selection when modelValue is omitted.
dir'ltr' | 'rtl'—Explicit text direction for horizontal roving.
disabledbooleanfalseDisables every item.
modelValueGhostToggleGroupValue—Controlled selection; shape follows type.
orientation'horizontal' | 'vertical'"horizontal"Arrow-key roving layout.
type'multiple' | 'single'"single"Single vs multiple pressed items.
SlotSlot propsDescription
default—Toggle group items.

@ghostvue/themes adds these to the headless GhostToggleGroup API, which it forwards:

PropTypeDefaultDescription
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 ​

PropTypeDefaultDescription
asGhostToggleGroupItemElement"button"Tag name or component for the toggle control.
disabledbooleanfalseDisables toggling and roving focus for this item.
valuestringRequiredStable value for this item in the group model.
SlotSlot propsDescription
default—Primary content.

Exposed: { element, focus(), blur() }.

Stable styling hooks ​

  • Classes: ghost-toggle-group, ghost-toggle-group-item
  • Attributes: data-ghost-toggle-group, data-ghost-toggle-group-value, data-part, data-state (on / off)

Themed styles ship from @ghostvue/themes (GhostToggleGroup, GhostToggleGroupItem).

Accessibility ​

  • Root: role="group" with an accessible name.
  • Items: native button (default) with aria-pressed="true" | "false".
  • Arrow keys move focus among enabled items; Home / End jump to ends.
  • Tab enters the group at the primary pressed item (or the first item).

Do not use radiogroup semantics for exclusive layout pickers when deselection should be allowed; use GhostRadioGroup when a permanent single choice is required.