# RadioGroup Primitive

RadioGroup is a Starwind Runtime primitive in the controlled-value-group contract family.
## Anatomy
### Astro
Use the Astro primitive adapter to render RadioGroup anatomy with the Runtime wiring included.
```astro
---
import { RadioGroup } from "@starwind-ui/astro/radio-group";
---

<RadioGroup.Root />
```

### React
Use the React primitive adapter when RadioGroup state participates in React rendering.
```tsx
import { RadioGroup } from "@starwind-ui/react/radio-group";

export function Example() {
  return (
    <RadioGroup.Root />
  );
}
```

### HTML
Render the RadioGroup data-sw-* contract yourself, then initialize createRadioGroup.
```html
<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 RadioGroup Runtime instance.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-radio-group` |
| Role | `radiogroup` |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| value | `RadioGroupValue` | - | control | Controls the current RadioGroup value. |
| defaultValue | `RadioGroupValue` | - | control | Sets the initial RadioGroup value for uncontrolled usage. |
| disabled | `boolean` | false | option | Disables the Root part. |
| form | `string` | - | option | Associates the control with a form element. |
| name | `string` | - | option | Sets the submitted form field name. |
| orientation | `"horizontal" \| "vertical"` | "vertical" | option | Sets the RadioGroup orientation. |
| readOnly | `boolean` | false | option | Marks the control as read-only. |
| required | `boolean` | false | option | Marks the form control as required. |
| onValueChange | `(value: string, details: RadioGroupValueChangeDetails) => void` | - | callback | Runs when the RadioGroup value changes. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-radio-group` | runtime | - | Marks the Root part so Starwind Runtime can find it. |
| `data-default-value` | prop | - | Reflects the default value prop on the Root part. |
| `data-disabled` | prop | - | Reflects the disabled prop on the Root part. |
| `data-form` | prop | - | Reflects the form prop on the Root part. |
| `data-name` | prop | - | Reflects the name prop on the Root part. |
| `data-orientation` | prop | - | Reflects the orientation prop on the Root part. |
| `data-readonly` | prop | - | Reflects the readonly prop on the Root part. |
| `data-required` | prop | - | Reflects the required prop on the Root part. |
| `data-value` | state | - | Reflects the value state on the Root part. |
#### State
| State | Value Type | Controlled Prop | Default Prop | Initial Attribute | Runtime Getter | Runtime Setter | Description | State Control Support |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| value | `RadioGroupValue` | value | defaultValue | `data-default-value` | `getValue` | `setValue` | Tracks the current RadioGroup value. | 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. |
#### Events
| Event | Callback | DOM Event | Value | Details | Timing | Cancelable | Description |
| --- | --- | --- | --- | --- | --- | --- | --- |
| valueChange | onValueChange | starwind:value-change | value: `string` | RadioGroupValueChangeDetails | - | - | Fires when the value changes for RadioGroup. |
#### Runtime Setters
| Method | Target | Options | Suppresses Emit | Description |
| --- | --- | --- | --- | --- |
| `setValue` | state: value | emit: false | Yes | Updates the current RadioGroup value from Runtime code. |
| `setDisabled` | prop: disabled | - | No | Updates whether RadioGroup is disabled from Runtime code. |
| `setFormOptions` | props: form, name, required | - | No | Updates RadioGroup form-related options from Runtime code. |
| `setName` | prop: name | - | No | Updates the RadioGroup form field name from Runtime code. |
| `setOrientation` | prop: orientation | - | No | Updates the RadioGroup orientation from Runtime code. |
| `setReadOnly` | prop: readOnly | - | No | Updates whether RadioGroup is read-only from Runtime code. |
| `setRequired` | prop: required | - | No | Updates whether RadioGroup is required from Runtime code. |
#### Refs
| Part | Public |
| --- | --- |
| root | Yes |
#### Context
| Name | Direction | Values |
| --- | --- | --- |
| radio-group | provides | disabled, form, name, readOnly, required, value |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-radio-group`, `role`, `aria-disabled`, `aria-orientation`, `aria-readonly`, `aria-required`, `data-default-value`, `data-disabled`, `data-form`, `data-name`, `data-orientation`, `data-readonly`, `data-required`, `data-value` | The radio group needs initial selection, form coordination, and orientation for child radio semantics before hydration. |
#### Form
| Fact | Value |
| --- | --- |
| Form props | form, name, required, value |
| Hidden input | - |
## Runtime API
| Fact | Value |
| --- | --- |
| Factory | [`createRadioGroup`](/docs/runtime/#create-radio-group) |
| Import | `@starwind-ui/runtime/radio-group` |
| Root part | root |
| Option props | defaultValue, disabled, form, name, orientation, readOnly, required, value |
| Option lifecycles | - |
## Form Participation
| Fact | Value |
| --- | --- |
| Form props | form, name, required, value |
| Hidden input | - |
| Field integration | Yes |
## Related Styled Components
| Component | Relationship |
| --- | --- |
| [Radio Group](/docs/components/radio-group/) | Composite |
## Exports
| Group | Import | Exports |
| --- | --- | --- |
| Runtime | `@starwind-ui/runtime/radio-group` | `createRadioGroup` |
| Astro Primitive | `@starwind-ui/astro/radio-group` | `RadioGroup`, `RadioGroupRoot` |
| React Primitive | `@starwind-ui/react/radio-group` | `RadioGroup`, `RadioGroupRoot` |
## Canonical Names
| Kind | Name |
| --- | --- |
| namespace | `RadioGroup` |
| runtime-factory | `createRadioGroup` |
| part | `RadioGroup.Root` |