Radio Group for Astro
Astro radio choices for one selected value in a related set.
Installation
bunx --bun shadcn@latest add @gnostic/radio-groupnpx shadcn@latest add @gnostic/radio-grouppnpm dlx shadcn@latest add @gnostic/radio-groupInstall component packages
bun add @data-slot/radio-groupnpm install @data-slot/radio-grouppnpm add @data-slot/radio-groupCopy the files
src/components/ui/radio-group/index.tssrc/components/ui/radio-group/radio-group-item.astrosrc/components/ui/radio-group/radio-group.astrosrc/components/ui/radio-group/types.ts
Usage
---
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
---
<RadioGroup defaultValue="option-one" name="example">
<div class="flex items-center gap-3">
<RadioGroupItem value="option-one" id="option-one" />
<Label for="option-one">Option One</Label>
</div>
<div class="flex items-center gap-3">
<RadioGroupItem value="option-two" id="option-two" />
<Label for="option-two">Option Two</Label>
</div>
</RadioGroup>
Composition
Arrange the parts as shown for a RadioGroup:
RadioGroup
├── RadioGroupItem
└── RadioGroupItem
Examples
With Descriptions
Radio group items with a title and supporting copy using the Field component.
Grid Layout
Wrap the whole row in FieldLabel when you want the entire card to act as the
click target.
With FieldSet
Use FieldSet and FieldLegend to group radio items with a shared label and
description.
Disabled
Use the disabled prop on RadioGroupItem to disable individual items.
API Reference
RadioGroupProps
defaultValue?string
Initial selected value
stringname?string
Form field name used by generated radio inputs
stringdisabled?boolean
Disable user interaction and form submission
booleanreadOnly?boolean
Prevent user interaction while keeping programmatic control
booleanrequired?boolean
Require a selected value for native form validation
booleanSee the data-slot docs for more information on interactivity.
Events
Dispatch these events on the radio group root. The root emits the outbound events.
Outbound events
| Event | Detail |
|---|---|
radio-group:change |
{ value: string | null } |
Inbound events
| Event | Detail |
|---|---|
radio-group:set |
{ value: string | null } |
Read the installed source for the complete prop types.
When to use Radio Group
Use Radio Group when all choices should be visible and only one can be selected. Give the group a name for form data and label each item. Use a fieldset and legend when the choices answer one question.
Keyboard and behavior
The data-slot controller maintains selection and keyboard movement. Test arrow keys and Space, then confirm the submitted form value. Disabled choices should remain understandable rather than disappearing without explanation.
Theme and layout
Selected borders and indicators use the primary token. Check long labels and the spacing between each indicator and its text. Invalid state needs an error message connected to the group.