Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

RadioGroup Primitive

RadioGroup is a Starwind Runtime primitive in the controlled-value-group contract family.

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 />

API Reference

Root

The main element that owns the RadioGroup Runtime instance.

Default element
div
Discovery hook
data-sw-radio-group
Role
radiogroup

Props

Prop Type Default Toggle
value RadioGroupValue -
Description
Controls the current RadioGroup value.
Kind
control
Targets
-
Full type
RadioGroupValue
defaultValue RadioGroupValue -
Description
Sets the initial RadioGroup value for uncontrolled usage.
Kind
control
Targets
-
Full type
RadioGroupValue
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 RadioGroup 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 RadioGroup value changes.
Kind
callback
Targets
-
Full type
(value: string, details: RadioGroupValueChangeDetails) => void

Events

Event Callback Value Toggle
valueChange onValueChange value: string
Description
Fires when the value changes for RadioGroup.
DOM event
starwind:value-change
Details type
RadioGroupValueChangeDetails
Timing
-
Cancelable
No

State

State Type Props Toggle
value RadioGroupValue value / defaultValue
Description
Tracks the current RadioGroup value.
Initial attribute
data-default-value
Runtime getter
getValue
Runtime setter
setValue
State control support
React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-default-value, emits starwind:value-change, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-radio-group - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-value - Reflects the value state on the Root part.
Metadata
Attribute Value Description
data-default-value - Reflects the default value 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-name - Reflects the name prop on the Root part.
data-orientation - Reflects the orientation 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.

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

Method Target Description
setValue state: value Updates the current RadioGroup value from Runtime code.
setDisabled prop: disabled Updates whether RadioGroup is disabled from Runtime code.
setFormOptions props: form, name, required Updates RadioGroup form-related options from Runtime code.
setName prop: name Updates the RadioGroup form field name from Runtime code.
setOrientation prop: orientation Updates the RadioGroup orientation from Runtime code.
setReadOnly prop: readOnly Updates whether RadioGroup is read-only from Runtime code.
setRequired prop: required Updates whether RadioGroup is required from Runtime code.

Form Participation

FactValue
Form propsform, name, required, value
Hidden input-
Field integrationYes
Component Relationship
Radio Group Composite