Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Radio Group for Astro

Astro radio choices for one selected value in a related set.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/radio-group

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.

Basic features for personal projects.

Advanced tooling for growing teams.

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.

Notifications

Choose how you want to be notified.

Disabled

Use the disabled prop on RadioGroupItem to disable individual items.

API Reference

RadioGroupProps

PropType
defaultValue?string

Initial selected value

Typestring
name?string

Form field name used by generated radio inputs

Typestring
disabled?boolean

Disable user interaction and form submission

Typeboolean
readOnly?boolean

Prevent user interaction while keeping programmatic control

Typeboolean
required?boolean

Require a selected value for native form validation

Typeboolean

See 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.