Radio Group

Loading...

Installation

Add the component with the CLI.

npx shadcn@latest add @intentui/radio

Composed components

When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.

Manual installation

Install the dependencies, then copy the component source into your project.

npm install react-aria-components cn

Anatomy

import { Description, Label } from "@/components/ui/field"
import { RadioField, RadioGroup, Radio } from "@/components/ui/radio"
<RadioGroup name="billing">
  <Label>Billing Cycle</Label>
  <Description>
    Select how often you'd like to be billed
  </Description>

  <RadioField value="monthly">
    <Radio>Monthly</Radio>
    <Description>Billed every month</Description>
  </RadioField>
  <RadioField value="quarterly">
    <Radio>Quarterly</Radio>
    <Description>Billed every 3 months</Description>
  </RadioField>
  <RadioField value="yearly">
    <Radio>Yearly</Radio>
    <Description>
      Billed once per year with a discount
    </Description>
  </RadioField>
</RadioGroup>

Examples

Orientation

By default, the radio group is vertically oriented. You can change it to a horizontal orientation by using the orientation prop.

Loading...

Without label

If you omit the visible label, provide an accessible name with aria-label or aria-labelledby.

Description

Add a description to the radio group by passing the description prop.

Loading...

Validation

Submit the form without selecting an option to see the validation error.

Loading...

Controlled

Pass value and update it with onChange to control the selected option.

Loading...

Uncontrolled

Use defaultValue to set the initial selection of an uncontrolled radio group.

Loading...

Disabled

When the radio group is disabled, it cannot be interacted with.

Loading...

Component API

RadioField

RadioField extends the React Aria Components <RadioField> component.

classNamestring

Radio

Radio extends the React Aria Components <RadioButton> component.

classNamestring

RadioGroup

RadioGroup extends the React Aria Components <RadioGroup> component.

classNamestring

See the React Aria for the full API reference.

Design