GhostRadioGroup specification
Status: Proposed for GHO-30. Spec and implementation ship together; Zac approves both in PR review.
Purpose and user problems
GhostRadioGroup is a native-first single-choice control for settings, filters, and forms. Sighted users pick one option from a short list. Assistive technology encounters a radiogroup with named options. Keyboard users rely on native radio group behavior: one tab stop per group, arrow keys move focus and select among options (including RTL), and Space operates the focused radio when applicable. The group participates in native HTML forms: shared name, one submitted value, and form reset restores the mounted default.
Consumers compose labeled options with GhostRadioGroupItem parts and optional GhostField for a group label, description, and error (Field supplies id/aria-describedby on the group root while items keep distinct ids for per-option labels).
Non-goals
- Multi-select or checkbox semantics. Use
GhostCheckboxor a future checkbox group. - Button-role toggles. Use
GhostToggleGroup(GHO-82). Card-style radio choices areGhostRadioCard, a card member of this group (see the choice cards spec). - Custom roving tabindex via
useRovingFocus. Native same-name radios already implement APG keyboard and tab-stop behavior; library roving conflicts with it. - Validation logic or message generation. Field and the consumer own invalid state.
- Visual styling in the headless package. Themed appearance lives in
@ghostvue/themes. true-value/false-valueboolean tricks. The v-model is the selected option's stringvalue.
Public API
Parts and exports
Headless @ghostvue/vue:
GhostRadioGroup— root container, v-model, form resetGhostRadioGroupItem— nativeinput type="radio"for one optionuseGhostRadioGroup— state and registration helpers for advanced composition- Types for props, exposed refs, options, and context
Themed @ghostvue/themes:
GhostRadioGroup,GhostRadioGroupItem— default vertical stack styles
Props and configuration
GhostRadioGroup
| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue | string | undefined | Controlled selected value. undefined is uncontrolled. |
defaultValue | string | undefined | Initial value when modelValue is omitted. Ignored after mount. Form reset restores this captured seed. |
name | string | undefined | Shared native name on item inputs for submit. When omitted, the group generates a stable useGhostId name so items still form a native group (pass an explicit name for forms you intend to submit). |
disabled | boolean | false | Disables the group (fieldset disabled or propagated to items). |
required | boolean | false | Native required on items when the group is required. |
invalid | boolean | false | Sets aria-invalid on the group root for Field integration. |
orientation | 'horizontal' | 'vertical' | 'vertical' | Themed layout only (data-orientation on the root). Does not change keyboard behavior. |
as | string | Component | 'fieldset' | Root element. Native fieldset does not need role="radiogroup". Non-fieldset hosts set role="radiogroup". |
Native attributes on the root fall through except reserved wiring (id may be overridden by Field slot props intentionally). GhostFieldControl slot props (id, disabled, required, aria-describedby, aria-invalid) spread onto the group root.
GhostRadioGroupItem
| Prop | Type | Default | Contract |
|---|---|---|---|
value | string | — | Stable option value; drives checked state and form value. |
disabled | boolean | false | Disables this option. Native group skips it for arrow navigation. |
Each item renders a native radio input. name comes from the group (explicit or generated). Optional fallthrough id (else useGhostId('ghost-radio-group-item')), aria-*, and listeners attach to the input. No default slot on the input; wrap in <label> or use for/id like GhostCheckbox.
v-model contracts
| Role | Prop | Emit | Uncontrolled initial |
|---|---|---|---|
| Selected | modelValue | update:modelValue | defaultValue, else none |
- Uncontrolled: omit
modelValue. Seed fromdefaultValuewhen provided; otherwise no item is checked at mount (native radios with nochecked). - Controlled: defined
modelValue. Activation (pointer or native keyboard) emitsupdate:modelValuewith the item'svalue. If the parent ignores the emit, restore native:checkedafternextTickon the activated input (same policy asGhostCheckbox). - Unregistering items: when the selected item unmounts, clear selection to
undefined. Do not pick another value. When controlled, do not emit; parent model unchanged until it reacts to DOM. When uncontrolled, internal state only. - Form reset: captured
defaultValueseed (not live props;undefinedmeans none checked). Deferred DOM reconciliation after fullresetdispatch viauseNativeFormReseton the group root's owning form. - Switching controlled ↔ uncontrolled after setup is unsupported (GHOST001).
Events, slots, and exposed methods
GhostRadioGroup default slot holds items. No scoped slot on the root.
GhostRadioGroupItem has no slot (void input).
Exposed template refs:
GhostRadioGroup:element: HTMLElement | null(root),focus/bluron the selected item if any, else the first enabled item (native tab order)GhostRadioGroupItem:element: HTMLInputElement | null,focus/blur
State model
| Condition | data-state on item | Native |
|---|---|---|
| Selected | checked | checked === true |
| Not selected | omitted | checked === false |
| Group or item disabled | omitted | disabled (native) |
Group root data-state: invalid when invalid is true; disabled when disabled and not invalid; else omitted.
Accessibility contract
Semantics
- Default root:
fieldsetwith consumer-providedlegendoraria-labelledby. - Items: native
input type="radio"with a sharedname(consumer or generated). - Keyboard and tab order follow the platform radio-group model per Radio Group APG. Arrow keys move focus and select. RTL is inherited from the root or ancestor
dir.
Keyboard
Native behavior only: arrow keys within the group select among same-name radios; Tab enters/leaves the group at the appropriate single tab stop; Space activates when applicable. No useRovingFocus.
Because the keys are native, these engine differences are intentional and covered by the @cross-browser e2e specs (Chromium, Firefox, WebKit):
- RTL horizontal arrows: Chromium and Firefox mirror ArrowLeft/ArrowRight in RTL (ArrowLeft moves to the next radio, which sits visually to the left). WebKit does not mirror them: ArrowRight always moves to the next radio in DOM order. ArrowDown/ArrowUp mean next/previous in every engine and direction.
- Backward Tab into an all-unchecked group: Chromium and Firefox focus the first radio; WebKit focuses the last. The group is still a single Tab stop, including inside
useFocusScopetraps.
Field integration
GhostField + GhostFieldControl spread bindings onto GhostRadioGroup. The group id is referenced by GhostFieldLabel (for). Description and error ids merge into aria-describedby on the group root. Per-option names use wrapping labels or for pointing at each item's id.
Composition
useControllableStatefor the selected valueuseNativeFormReseton the group root (HTMLFieldSetElement.form)useGhostIdfor generated groupnameand per-item ids- Does not use
useRovingFocusoruseFocusScope
Test plan
- Vue: v-model, uncontrolled none-selected mount,
defaultValueseed, disabled group/item, controlled emit ignore + nextTick restore, form reset seed, generatedname, unregister clears selection without fallback emit, Field aria wiring - Browser: arrow selects without Space, shared
namewhennameprop omitted, RTL horizontal arrows, form submit with selected value, axe on examples and playground - Cross-browser (
tests/e2e/rtl-roving.spec.ts,tests/e2e/focus.spec.ts): RTL layout geometry, arrow focus pluscheckedstate, and native radio Tab cycles in focus traps, with the per-engine expectations listed under Keyboard - Integration: themed wrapper
elementref - Type: consumer compile fixtures
Documentation plan
docs/components/radio-group.md, examples under examples/radio-group/ (basic, field, form, themed), playground section with unique copy.
Compatibility and release impact
Additive minor Changesets for @ghostvue/vue and @ghostvue/themes.
Open architectural questions
None blocking.