Skip to main content

Starwind UI v3.0 is now available! Migration guide

Radio Primitive

Radio is a Starwind Runtime primitive in the single-boolean-control 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 Radio anatomy with the Runtime wiring included.

---
import { Radio } from "@starwind-ui/astro/radio";
---
<Radio.Root value="option-one">
<Radio.Indicator />
</Radio.Root>

API Reference

Root

The main element that owns the Radio Runtime instance.

Default element
span
Discovery hook
data-sw-radio
Role
radio

Props

Prop Type Default Toggle
checked boolean -
Description
Controls whether Radio is checked.
Kind
control
Targets
-
Full type
boolean
React

Use checked for controlled state and defaultChecked for default state, and onCheckedChange for change proposals.

  • checked
  • defaultChecked
  • onCheckedChange
Astro

Use checked or defaultChecked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • checked
  • defaultChecked
  • starwind:checked-change
  • setChecked
Runtime / HTML

Use data-default-checked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • data-default-checked
  • starwind:checked-change
  • setChecked
defaultChecked boolean false
Description
Sets whether Radio starts checked for uncontrolled usage.
Kind
control
Targets
-
Full type
boolean
React

Use checked for controlled state and defaultChecked for default state, and onCheckedChange for change proposals.

  • checked
  • defaultChecked
  • onCheckedChange
Astro

Use checked or defaultChecked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • checked
  • defaultChecked
  • starwind:checked-change
  • setChecked
Runtime / HTML

Use data-default-checked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • data-default-checked
  • starwind:checked-change
  • setChecked
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
id string -
Description
Sets the id used by the associated native control.
Kind
option
Targets
-
Full type
string
name string -
Description
Sets the submitted form field name.
Kind
option
Targets
-
Full type
string
nativeButton boolean false
Description
Renders the control as a native button element.
Kind
rendering
Targets
root
Full type
boolean
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
value string -
Description
Controls the current Radio value.
Kind
option
Targets
-
Full type
string
onCheckedChange (checked: boolean, details: RadioCheckedChangeDetails) => void -
Description
Runs when the Radio checked state changes.
Kind
callback
Targets
-
Full type
(checked: boolean, details: RadioCheckedChangeDetails) => void
React

Use checked for controlled state and defaultChecked for default state, and onCheckedChange for change proposals.

  • checked
  • defaultChecked
  • onCheckedChange
Astro

Use checked or defaultChecked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • checked
  • defaultChecked
  • starwind:checked-change
  • setChecked
Runtime / HTML

Use data-default-checked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • data-default-checked
  • starwind:checked-change
  • setChecked

Events

Event Callback Value Toggle
checkedChange onCheckedChange checked: boolean
Description
Fires when the checked state changes for Radio.
DOM event
starwind:checked-change
Details type
RadioCheckedChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.

State

State Type Props Toggle
checked boolean checked / defaultChecked
Description
Tracks whether Radio is checked.
Initial attribute
data-default-checked
Runtime getter
getChecked
Runtime setter
setChecked
React

Use checked for controlled state and defaultChecked for default state, and onCheckedChange for change proposals.

  • checked
  • defaultChecked
  • onCheckedChange
Astro

Use checked or defaultChecked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • checked
  • defaultChecked
  • starwind:checked-change
  • setChecked
Runtime / HTML

Use data-default-checked for initial state, listen for starwind:checked-change, and call setChecked for later updates.

  • data-default-checked
  • starwind:checked-change
  • setChecked

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-radio - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-checked - Reflects the checked state on the Root part.
data-unchecked - Reflects the unchecked state on the Root part.
Metadata
Attribute Value Description
data-default-checked - Reflects the default checked prop on the Root part.
data-disabled - Reflects the disabled prop on the Root part.
data-form - Reflects the form prop on the Root part.
data-id - Reflects the id prop on the Root part.
data-name - Reflects the name prop on the Root part.
data-readonly - Reflects the readonly prop on the Root part.
data-required - Reflects the required prop on the Root part.
data-value - Reflects the value prop on the Root part.

Indicator

Visual state indicator rendered by Radio.

Default element
span
Discovery hook
data-sw-radio-indicator
Role
-

Props

Prop Type Default Toggle
keepMounted boolean false
Description
Keeps the Indicator part in the DOM when hidden.
Kind
rendering
Targets
indicator
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-radio-indicator - Marks the Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-unchecked - Reflects the unchecked state on the Indicator part.
Metadata
Attribute Value Description
data-keep-mounted - Reflects the keep mounted prop on the Indicator part.

Input

The native input synchronized by Radio.

Default element
input
Discovery hook
data-sw-radio-input
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-radio-input - Marks the Input part so Starwind Runtime can find it.

Runtime API

Factory
createRadio
Import
@starwind-ui/runtime/radio
Root hook
root data-sw-radio
Option props
checked, defaultChecked, disabled, form, id, name, readOnly, required, value

Runtime Setters

Method Target Description
setChecked state: checked Updates whether Radio is checked from Runtime code.
setDisabled prop: disabled Updates whether Radio is disabled from Runtime code.
setReadOnly prop: readOnly Updates whether Radio is read-only from Runtime code.
setFormOptions props: form, name, required, value Updates Radio form-related options from Runtime code.

Form Participation

FactValue
Form propsform, id, name, required, value
Hidden inputinput (radio)
Field integrationYes
Component Relationship
Radio Group Composite

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 state after accepted Runtime transitions and external state changes.

v0.1.0

  • Introduced radio item checked state, disabled behavior, and native form participation.