Radio Group Primitive
Radio Group is a Starwind Runtime primitive in the controlled-value-group contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
Anatomy
Use the Astro primitive adapter to render RadioGroup anatomy with the Runtime wiring included.
---import { RadioGroup } from "@starwind-ui/astro/radio-group";---
<RadioGroup.Root />Use the React primitive adapter when RadioGroup state participates in React rendering.
import { RadioGroup } from "@starwind-ui/react/radio-group";
export function Example() { return ( <RadioGroup.Root /> );}Render the RadioGroup data-sw-* contract yourself, then initialize createRadioGroup.
<div data-sw-radio-group role="radiogroup"></div>
<script type="module"> import { createRadioGroup } from "@starwind-ui/runtime/radio-group";
const root = document.querySelector("[data-sw-radio-group]"); if (root) { createRadioGroup(root); }</script>API Reference
Root
The main element that owns the Radio Group Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-radio-group
- Role
- radiogroup
Props
value RadioGroupValue -
- Description
- Controls the current Radio Group value.
- Kind
- control
- Targets
- -
- Full type
- RadioGroupValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
defaultValue RadioGroupValue -
- Description
- Sets the initial Radio Group value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- RadioGroupValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
disabled boolean false
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
form string -
- Description
- Associates the control with a form element.
- Kind
- option
- Targets
- -
- Full type
- string
name string -
- Description
- Sets the submitted form field name.
- Kind
- option
- Targets
- -
- Full type
- string
orientation "horizontal" | "vertical" "vertical"
- Description
- Sets the Radio Group orientation.
- Kind
- option
- Targets
- -
- Full type
- "horizontal" | "vertical"
readOnly boolean false
- Description
- Marks the control as read-only.
- Kind
- option
- Targets
- -
- Full type
- boolean
required boolean false
- Description
- Marks the form control as required.
- Kind
- option
- Targets
- -
- Full type
- boolean
onValueChange (value: string, details: RadioGroupValueChangeDetails) => void -
- Description
- Runs when the Radio Group value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: string, details: RadioGroupValueChangeDetails) => void
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Events
valueChange onValueChange value: string
- Description
- Fires when the value changes for Radio Group.
- DOM event
- starwind:value-change
- Details type
- RadioGroupValueChangeDetails
- Timing
- before-state-commit
- Cancelable
- Yes
- Cancellation sequence
- Check internal eligibility and intent.
- Create one details object for the proposal.
- Call the Runtime callback with the details object when the controller exposes one.
- Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
- Read details.isCanceled, including cancellation caused by preventDefault().
- Apply the accepted state.
- Notify Runtime subscribers and other accepted-only observers.
State
value RadioGroupValue value / defaultValue
- Description
- Tracks the current Radio Group value.
- Initial attribute
- data-default-value
- Runtime getter
- getValue
- Runtime setter
- setValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
Runtime API
- Factory
createRadioGroup- Import
@starwind-ui/runtime/radio-group- Root hook
- root
data-sw-radio-group - Option props
- defaultValue, disabled, form, name, orientation, readOnly, required, value
Runtime Setters
Form Participation
| Fact | Value |
|---|---|
| Form props | form, name, required, value |
| Hidden input | - |
| Field integration | Yes |
Related Styled Components
Changelog
View version history v1.0.0 4 releases
v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
v0.1.2
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
- Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.
v0.1.1
- Synchronized vendored React Radio Group state after accepted Runtime transitions and external state changes.
v0.1.0
- Introduced grouped radio ownership, roving keyboard focus, value changes, and form participation.