GhostToggleGroup specification
Status: Proposed for GHO-82. Spec and implementation ship together; Zac approves both in PR review.
Amendment (approved 2026-12-03): a
sizeprop on the themedGhostToggleGroupis recorded in the Control size amendment. The maintainer @zprue743 approved the recommended contract decision (Q1–Q4) on 2026-12-03.
Purpose and user problems
GhostToggleGroup groups related on/off toggle buttons so users can choose one or several options from a small set—table density controls, layout switches, segmented filters, and formatting toolbars. Applications need toggle-button semantics (aria-pressed), not radio-group semantics, so a pressed option can be toggled off and multiple options can stay on independently when configured. The component composes useControllableState, useGhostId, and useRovingFocus for APG-correct keyboard movement, controlled Vue models, and SSR-safe ids without reimplementing roving tabindex.
Non-goals
- Exclusive single-choice form controls with radio semantics (
GhostRadioGroup). - Arbitrary toolbar composites with menu buttons (
GhostToolbar,GhostDropdownMenu). - Form submission values for the group (toggle buttons are not submitted as a group; consumers own form wiring if needed).
- Animated segmented indicators, overflow “more” menus, or drag reordering.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostToggleGroup(rootrole="group"host with roving focus)GhostToggleGroupItem(aria-pressedtoggle control)useGhostToggleGroup(selection state, registries, toggle helpers)- Types:
GhostToggleGroupProps,GhostToggleGroupItemProps,GhostToggleGroupExposed,GhostToggleGroupItemExposed,UseGhostToggleGroupOptions,UseGhostToggleGroupReturn,GhostToggleGroupType,GhostToggleGroupOrientation,GhostToggleGroupValue
Themed exports from @ghostvue/themes:
GhostToggleGroup,GhostToggleGroupItem(plus re-exported types and styles viadefault.css)
Props and configuration
GhostToggleGroup (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
type | 'single' | 'multiple' | 'single' | Single allows zero or one pressed item; multiple allows any subset. |
modelValue | string | string[] | undefined | undefined | Controlled selection. Omit for uncontrolled. Type must match type. |
defaultValue | string | string[] | undefined | undefined | Initial selection when uncontrolled. Multiple defaults to [] when omitted. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Drives roving arrow keys and optional aria-orientation on the group. |
dir | 'ltr' | 'rtl' | undefined | undefined | Explicit text direction for horizontal roving. |
as | string | Component | 'div' | Root element hosting items. Must remain focusable as a group container (not button). |
disabled | boolean | false | Disables interaction for all items (items still render; items’ own disabled also applies). |
GhostToggleGroupItem
| Prop | Type | Default | Contract |
|---|---|---|---|
as | string | Component | 'button' | Element or component for the control. |
value | string | required | Stable id for selection and v-model. |
disabled | boolean | false | Skips roving focus and ignores toggle. Native disabled on <button>; aria-disabled otherwise. |
Native attributes and listeners fall through to each part’s rendered root.
v-model contracts
GhostToggleGroup owns modelValue via useControllableState:
- When
modelValueisundefined(omitted), internal state starts atdefaultValuewhen provided. - In
type="single"uncontrolled mode withoutdefaultValue, no item is pressed initially. - In
type="multiple"uncontrolled mode withoutdefaultValue, internal state is[]. update:modelValueemits on every user-driven toggle while uncontrolled; controlled consumers must apply the emitted value.- Single: emitted value is
string | undefined(pressing the active item clears selection). - Multiple: emitted value is
string[](order follows registration order, not click order). valuestrings are opaque; duplicates among items are unsupported (last registration wins for roving maps).
Events, callbacks, slots, and exposed methods
GhostToggleGroupemitsupdate:modelValuewith[value: string | string[] | undefined].GhostToggleGroupdefault slot holds items (no slot props).GhostToggleGroupandGhostToggleGroupItemexpose{ element: HTMLElement | null, focus(), blur() }.
State model
- Single: at most one pressed item; pressing the pressed item clears selection (
undefined). - Multiple: any subset; pressing toggles membership.
data-state="on" | "off"on items mirrors pressed state.- Group
disabledprevents all toggles without removing items from the DOM.
Loading, empty, disabled, read-only, and error states
Per-item disabled and group disabled only. No loading or read-only mode.
Consumer data
The component does not mutate consumer collections. Item labels are slot content.
Accessibility contract
Uses WAI-ARIA toggle button semantics inside a group, not radiogroup / radio.
Semantics and relationships
GhostToggleGroup:role="group", optionalaria-orientationwhen vertical,aria-disabled="true"when group disabled,data-part="root", classghost-toggle-group,data-ghost-toggle-group.GhostToggleGroupItem: nativebutton(default) withtype="button",aria-pressed="true" | "false", deterministicidfromuseGhostId(overridable viaid),data-part="item", classghost-toggle-group-item,data-ghost-toggle-group,data-ghost-toggle-group-value.- Consumers must label the group via
aria-label,aria-labelledby, or visible text plusaria-labelledby. Each item is named by its visible content oraria-label.
Keyboard interaction
Roving among items (useRovingFocus on the group root):
| Key | Orientation | Behavior |
|---|---|---|
ArrowRight | horizontal | Next enabled item (RTL: previous). |
ArrowLeft | horizontal | Previous enabled item (RTL: next). |
ArrowDown | vertical | Next enabled item. |
ArrowUp | vertical | Previous enabled item. |
Home | either | First enabled item. |
End | either | Last enabled item. |
Arrow, Home, and End combined with Alt, Ctrl, or Meta, and keys that belong to an IME composition, are not handled so platform shortcuts keep working.
Activation (GhostToggleGroupItem):
| Key | Behavior |
|---|---|
Space/Enter | Toggles pressed state (native on <button>). |
| Click | Toggles pressed state. |
Disabled items are skipped by roving focus and cannot be toggled.
Focus behavior
- The primary tab stop is the first pressed enabled item in registration order; if none are pressed, the first enabled item. Other enabled items use
tabindex="-1"(including native<button>hosts). - Arrow keys move focus via
useRovingFocus. When focus leaves the group, tab stops reset to the primary stop so a laterTabinto the group focuses the expected pressed (or first) item, not the last arrow-focused item. - Tab moves into and out of the group at the primary stop only.
Assistive technology expectations
Screen readers announce the group label and each item as a toggle button with pressed state via aria-pressed, distinguishing this widget from radio groups where deselecting the checked option is not allowed.
Rendering and customization
Stable hooks (not the undecided GHO-38 styling-hooks contract):
ghost-toggle-group,ghost-toggle-group-itemclassesdata-part,data-state,data-ghost-toggle-group,data-ghost-toggle-group-value- Themed CSS under
.ghost-theme/.ghost-themed-scopeusing existing--ghost-*semantic tokens (segmented control appearance)
Environment behavior
SSR and hydration
useGhostIdsupplies deterministic SSR-safe ids.useRovingFocusattaches listeners only inonMounted(nodocumentaccess during SSR setup).
Mobile and touch
Pointer activation toggles items; no separate gesture model.
Performance
Listeners are limited to roving keydown/focusin on the group root while mounted.
Composition
useGhostToggleGroup+useControllableStatefor selection.useGhostIdper item (when needed for labeling wiring).useRovingFocusonGhostToggleGrouproot.- Shared tab-stop sync helper modeled on tabs selection tab stops.
Test plan
- Unit (
GhostToggleGroup.test.ts): single/multiple toggle, deselect in single mode, group disabled, item disabled, horizontal/vertical arrows, RTL, Home/End, controlled/uncontrolled,aria-pressed, SSR without roving listeners. - Browser (
ghost-toggle-group.spec.ts): example gallery keyboard/pointer, Axe zero violations,@component:GhostToggleGroup. - Cross-browser (
rtl-roving.spec.ts,@cross-browser): RTL layout order, mirrored arrows with real focus whilearia-pressedonly changes on Space, in Chromium, Firefox, and WebKit. No engine differences found; focus and ARIA assertions are shared. - Themed integration: themed root ref reaches group element.
- Type tests: consumer fixtures for single vs multiple
v-modelwhen exports stabilize.
Documentation plan
docs/components/toggle-group.mdwith headless and themed examples.- Registry entries for
toggle-group/basic,toggle-group/multiple,toggle-group/themed. - Playground
ToggleGroupReferencesection with unique copy. - Manifests via
pnpm manifests:write.
Compatibility and release impact
Additive minor Changeset for @ghostvue/vue and @ghostvue/themes.
Open architectural questions
None.
Control size amendment
Important
Approved 2026-12-03 by @zprue743. This amendment adds a size prop to the themed GhostToggleGroup. The contract decision records the chosen options. Target release: 0.4.0.
Why a size option
The themed track is one medium control tall (control.size.md.min). In a toolbar of size="sm" buttons and inputs it is taller than its neighbours, and there is no supported way to match them. App builders hit this with reaction toggles under chat messages and with formatting toggles in a compact toolbar.
The same gap exists on GhostSegmentedControl, GhostTabsList and GhostSelectTrigger. Each spec carries a matching amendment, so all four follow GhostButton and GhostInput, which already take size: 'sm' | 'md' | 'lg'.
Public API
Themed GhostToggleGroup in @ghostvue/themes only:
| Prop | Type | Default | Contract |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Track height, label size and item padding follow control.size.<size>, matching a GhostButton or GhostInput of the same size. |
- The union is exported as
GhostToggleGroupSize, followingGhostButtonSizeandGhostInputSize. - The wrapper renders
data-size="sm"ordata-size="lg"on the root and omits it formd, asGhostButtonandGhostInputdo. The wrapper consumessize, so it never reaches the DOM as asizeattribute. data-sizeon the root is the styling hook. A headlessGhostToggleGroupinside.ghost-themethat setsdata-sizeitself gets the same sizing, as withGhostButton.GhostToggleGroupItemtakes nosize. Every item in a track uses the root size.- Headless
@ghostvue/vuedoes not change: no prop, type or manifest change.
Sizing contract
For each size, S below means control.size.<size>.
- Height (fine pointers, horizontal). The root's border-box block size equals
S.min, the same as aGhostInputwith the samesizein the same density. This holds at device scale factor 1 and 2. Labels that wrap may still grow the track, as today. - Label and padding. Label font size is
S.font. Item inline padding isS.padding.inline. The track's inset and border do not change with size. - Tokens only. No recipe sets its own height, padding or pixel value. Densities change
S.*and the control follows. - Vertical. Each item keeps the current per-item minimum rule, computed from
S.mininstead ofcontrol.size.md.min. - Coarse pointers. Each item still takes the whole control height as its minimum, read from
S.min. The generated tokens setsm,mdandlgto the same 44px minimum under(pointer: coarse)in every density, sosmnever shrinks a touch target. - Device scale factor 2. The current item minimum is the control size less twice the track inset and twice
--ghost-border-hairline-width. At device scale factor 2 that token resolves to0.5px, but Chromium computes the track'sborder-top-widthas1px. Measured on the playground exampletoggle-group/themed: the track is 36px at 1x and 37px at 2x, beside a 36pxcontrol.size.md.min. The size guarantee above must hold at 2x, so it cannot depend on that subtraction for the horizontal track. One way is to give the trackmin-block-size: S.minwithbox-sizing: border-boxand let items stretch to fill it. The implementation chooses the mechanism; the acceptance cases fix the outcome.
Accessibility
Roles, names, states, keyboard and focus do not change. The item is the activation target and is shorter than the track by the inset and border. At sm in compact density (28px control, 4px inset) a horizontal item is about 18px tall. This is the same situation as md in compact density today (about 22px). WCAG 2.2 target size (2.5.8) is met through its spacing exception: only the track's own inset lies above and below a horizontal item, and items are wider than 24px. An acceptance case checks this geometry. Coarse pointers keep the 44px minimum.
Implementation acceptance cases
- Size parity (browser). A playground fixture renders one row per density (
compact,comfortable,spacious). Each row holdsGhostButton,GhostInputandGhostToggleGroupatsm,mdandlg. At every size and density, the root's border-box block size equals theGhostInputof the same size (difference under 0.5px). One fixture serves all four amended components. - Device scale factor 2. The parity comparison also runs in Chromium at
deviceScaleFactor: 2for the horizontal track at every size. - Target geometry. At
smin compact density, a horizontal item is wider than 24px and only the track's inset lies above and below it. - Default unchanged. Omitting
sizerenders nodata-size. At device scale factor 1 thetoggle-group/themedexample renders as it does today. - Coarse pointer. With
isMobileandhasTouch, every activation target is at least 44px tall at every size. - Wrapper (unit).
size="sm"andsize="lg"render the matchingdata-size;mdand an omittedsizerender none. Nosizeattribute reaches the DOM. A type test rejectssize="xl"onGhostToggleGroup. - Manifests and API tables.
pnpm manifests:writerecords the prop inpackages/themes/manifests/ghost-toggle-group.manifest.json, andpnpm docs:api:writeupdates the generated API table.
Documentation plan
- A Size section in
docs/components/toggle-group.mdwith one runnable example showing a toggle group atsize="sm"beside a smallGhostButtonandGhostInput. - Generated API tables and the themed manifest list the prop.
- A
@ghostvue/themesChangeset.
Compatibility
Additive. The default stays md. A size attribute passed today falls through to the root div and has no effect; after the change it is a typed prop. At device scale factor 2 in Chromium, a default md track becomes 1px shorter (37px to 36px), which is the fix the size guarantee requires. Minor Changeset for @ghostvue/themes.
Contract decision
Recorded 2026-12-03. @zprue743 took the recommended option for each question, and Q1, Q2 and Q4 have the same answer in all four amended specs. Each question lists the chosen option first and the rejected alternative after it.
- Q1 — Where
sizelives. Chosen: on the root only. Items take nosize, so one track never mixes heights. - Q2 — Themed only. Chosen:
sizebelongs to the themed wrappers, as forGhostButtonandGhostInput. Headless components stay unstyled anddata-sizeis the styling hook. Rejected: addsizeto the headless props as a data attribute only. - Q3 — The 2x guarantee. Chosen: guarantee equal heights with
GhostInputat device scale factor 1 and 2, and accept the 1px change to the defaultmdtrack at 2x in Chromium. Rejected: guarantee 1x only and track the 2x difference separately. - Q4 — Release and delivery. Chosen:
0.4.0, with all four components in one implementation change so they share the parity fixture. Rejected: one change per component, in the order segmented control, toggle group, select trigger, tabs.