GhostSegmentedControl specification
Status: Proposed for GHO-101. Spec and implementation ship together; Zac approves both in PR review.
Amendment (approved 2026-12-03): a
sizeprop on the themedGhostSegmentedControlis recorded in the Control size amendment. The maintainer @zprue743 approved the recommended contract decision (Q1–Q4) on 2026-12-03.
Purpose and user problems
GhostSegmentedControl is a styled single-select control for switching views, layout modes, or filters where one segment is always visually active—a segmented bar with a sliding selection indicator. It reuses GhostToggleGroup / useGhostToggleGroup toggle-button semantics (aria-pressed, roving focus) rather than radio semantics, because the same headless model already powers toolbar toggles and only needs a different chrome.
Consumers get equal-width segments, a theme token–driven sliding thumb, and prefers-reduced-motion support without wiring layout measurements.
Non-goals
- Multiple independent selections (
type="multiple"). UseGhostToggleGroup. - Radio / form submission semantics (
GhostRadioGroup). - Per-segment unequal widths driven by
getBoundingClientRector other post-layout reads (equal1/nsegments only; see Sizing). - Overflow menus, drag reorder, or icons-only segments without visible labels.
- Changing
GhostToggleGrouppublic props or behavior.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostSegmentedControl(rootrole="group"with slidingdata-part="indicator")GhostSegmentedControlItem(aria-pressedsegment)useGhostSegmentedControl(single-mode toggle group + indicator indices)- Types:
GhostSegmentedControlProps,GhostSegmentedControlItemProps,GhostSegmentedControlExposed,GhostSegmentedControlItemExposed,GhostSegmentedControlValue,GhostSegmentedControlOrientation,UseGhostSegmentedControlOptions,UseGhostSegmentedControlReturn
Themed exports from @ghostvue/themes:
GhostSegmentedControl,GhostSegmentedControlItem(plus types and styles viadefault.css)
Props and configuration
GhostSegmentedControl (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue | string | undefined | undefined | Controlled selection. Omit for uncontrolled. |
defaultValue | string | undefined | undefined | Initial selection when uncontrolled. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Roving arrows and indicator slide axis. |
dir | 'ltr' | 'rtl' | undefined | undefined | Explicit text direction for horizontal roving. |
as | string | Component | 'div' | Root host; must not be interactive. |
disabled | boolean | false | Disables every item. |
deselectable | boolean | false | When false, pressing the active segment keeps it pressed (typical view switching). |
GhostSegmentedControlItem
Same contract as GhostToggleGroupItem: as (default 'button'), required value, optional disabled.
Native attributes fall through to each part’s rendered root.
v-model contracts
modelValue is string | undefined. Behavior follows single-mode useGhostToggleGroup except when deselectable is false: clicking the active segment does not emit undefined. Controlled consumers must apply emitted values on user interaction while uncontrolled.
Events, callbacks, slots, and exposed methods
- Emits
update:modelValuewith[value: string | undefined]. - Default slot holds items (no slot props).
- Root and items expose
{ element, focus(), blur() }.
State model
- At most one pressed item (
aria-pressed="true"). data-state="on" | "off"on items.- Root sets CSS variables from registration order (never from layout):
--ghost-segmented-item-count,--ghost-segmented-selected-index(-1when none selected). - Sliding
data-part="indicator"is present in SSR markup; position uses those variables only.
Loading, empty, disabled, read-only, and error states
Group and per-item disabled only.
Consumer data
The component does not mutate consumer collections. Labels are slot content.
Accessibility contract
WAI-ARIA toggle button in a group, matching GhostToggleGroup single mode.
Semantics and relationships
- Root:
role="group", optionalaria-orientationwhen vertical,aria-disabledwhen disabled,data-part="root", classghost-segmented-control,data-ghost-segmented-control. - Indicator:
data-part="indicator",aria-hidden="true", not focused. - Item: native
buttondefault,type="button",aria-pressed,useGhostId,data-part="item", classghost-segmented-control-item,data-ghost-segmented-control,data-ghost-segmented-control-value. - Group label via
aria-labeloraria-labelledby.
Keyboard interaction
Same roving and activation table as GhostToggleGroup (arrows, Home, End, Space/Enter, click). Disabled items skipped.
Focus behavior
Same primary tab stop rules as GhostToggleGroup via applyToggleGroupSelectionTabStops.
Assistive technology expectations
Toggle buttons with pressed state—not radios.
Rendering and customization
- Classes:
ghost-segmented-control,ghost-segmented-control-item,ghost-segmented-control-indicator - Attributes:
data-ghost-segmented-control,data-ghost-segmented-control-value,data-part,data-state - Themed CSS under
.ghost-themeusing--ghost-*tokens; indicator motion uses--ghost-motion-*with@media (prefers-reduced-motion: reduce)snapping position without transition.
Sizing
The indicator is positioned as an equal 1/n fraction of the padded track, so the themed layout must give every segment exactly 1/n of the track width (or height when vertical). The supported sizing contract:
- Default: the root is an
inline-gridofminmax(0, 1fr)columns. It sizes to content, and every column takes the widest label's width. - Full width: set
display: grid(or a definitewidth) on the root; the columns stay equal across the container. - Constrained width: label text wraps inside each segment so the indicator covers the text while the tracks stay equal.
- Flex override (compatibility): a root overridden to block-level
display: flex(which fills its container) or given an explicit width keeps equal segments through the items'flex: 1 1 0andmin-width: 0fallback. A shrink-to-fitinline-flexroot can make long labels wrap even when the container has space for a wider control. - Vertical: controls stack equal
minmax(0, 1fr)rows atmax-contentwidth. Every row takes the tallest label's height, so rows stay equal when a constrained width makes one label wrap. A vertical root overridden todisplay: flexusesflex-direction: column, and its rows stay equal only while every label has the same height (for example, single-line labels). A column flex root has no definite height to split, so each row takes its own label's height. Amin-height: 0reset would collapse auto-height roots instead, so it is not applied. Keep the default grid when vertical labels can wrap.
Environment behavior
SSR and hydration
- Item count and selected index come from registration order and model value only.
- No
window/documentlayout reads during SSR setup for indicator position. - Indicator markup is identical server and client for the same props/state.
useRovingFocusattaches listeners inonMountedonly (inherited pattern).
Mobile and touch
Pointer toggles segments; equal-width 1/n targets per Sizing.
Performance
One passive indicator element; roving listeners on the group root while mounted.
Composition
useGhostSegmentedControldelegates touseGhostToggleGroupwithtype: 'single'.useGhostId,useRovingFocus,applyToggleGroupSelectionTabStops.- No changes to
GhostToggleGroup.vueor its exported props.
Test plan
- Unit (
GhostSegmentedControl.test.ts): selection,deselectable, disabled, roving keys, controlled/uncontrolled, indicator CSS variables,aria-pressed, SSR HTML includes indicator variables. - SSR hydration:
expectSsrHydrationwith default selection and ids. - Browser (
ghost-segmented-control.spec.ts): pointer/keyboard, Axe,@component:GhostSegmentedControl. Geometry checks assert the indicator matches the selected segment for unequal labels (docs home) and that a full-widthdisplay: flexoverride (popover/share-settings, indocs-popover-showcase.spec.ts) keeps every segment at1/nof the track. A vertical sizing check keeps rows equal under the indicator for a narrow-width grid with one wrapping label, and for adisplay: flexoverride with single-line labels. The RTL indicator alignment and mirrored roving case is tagged@cross-browserand also runs in Firefox and WebKit. - Themed integration: themed wrapper ref reaches root.
- Visual:
segmented-control/themedinexamples-visualviapnpm test:visual:docker.
Documentation plan
docs/components/segmented-control.mdwith examples.- Registry:
segmented-control/basic,segmented-control/themed. - Playground
SegmentedControlReference. - 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 GhostSegmentedControl. 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 in a toolbar, in reaction toggles under chat messages, and in a compact Light/Dark switch in a header.
The same gap exists on GhostToggleGroup, 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 GhostSegmentedControl in @ghostvue/themes only:
| Prop | Type | Default | Contract |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Track height, label size and segment padding follow control.size.<size>, matching a GhostButton or GhostInput of the same size. |
- The union is exported as
GhostSegmentedControlSize, 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 headlessGhostSegmentedControlinside.ghost-themethat setsdata-sizeitself gets the same sizing, as withGhostButton.GhostSegmentedControlItemtakes nosize. Every segment 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. Segment inline padding isS.padding.inline. The track's inset and border do not change with size, so the indicator geometry does not change. - Tokens only. No recipe sets its own height, padding or pixel value. Densities change
S.*and the control follows. - Vertical. Each segment keeps the current per-segment minimum rule, computed from
S.mininstead ofcontrol.size.md.min. - Coarse pointers. Each segment 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 segment 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 examplesegmented-control/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 segments 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 segment 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 segment 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 segment, and segments 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,GhostInputandGhostSegmentedControlatsm,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 segment is wider than 24px and only the track's inset lies above and below it. - Indicator. At
smandlgthe indicator still matches the selected segment, using the existing geometry check for unequal labels. - Default unchanged. Omitting
sizerenders nodata-size. At device scale factor 1 thesegmented-control/themedvisual snapshot does not change. - 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"onGhostSegmentedControl. - Manifests and API tables.
pnpm manifests:writerecords the prop inpackages/themes/manifests/ghost-segmented-control.manifest.json, andpnpm docs:api:writeupdates the generated API table.
Documentation plan
- A Size section in
docs/components/segmented-control.mdwith one runnable example showing a segmented control 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. Segments 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.