Radio Group

A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.

@react.component
let make = () =>
  <RadioGroup defaultValue="comfortable" className="w-fit">

Installation

npx shadcn@latest add @rescript-shadcn/RadioGroup

Usage

<RadioGroup defaultValue="option-one">
  <div className="flex items-center gap-3">
    <RadioGroup.Item value="option-one" id="option-one" />
    <Label htmlFor="option-one"> {"Option One"->React.string} </Label>
  </div>
  <div className="flex items-center gap-3">
    <RadioGroup.Item value="option-two" id="option-two" />
    <Label htmlFor="option-two"> {"Option Two"->React.string} </Label>
  </div>
</RadioGroup>

Examples

Description

Radio group items with a description using the Field component.

@react.component
let make = () =>
  <RadioGroup defaultValue="comfortable" className="w-fit">

Choice Card

Use FieldLabel to wrap the entire Field for a clickable card-style selection.

@react.component
let make = () =>
  <RadioGroup defaultValue="plus" className="max-w-sm">

Fieldset

Use FieldSet and FieldLegend to group radio items with a label and description.

@react.component
let make = () =>
  <Field.Set className="w-full max-w-xs">

Disabled

Use the disabled prop on RadioGroup to disable all items.

@react.component
let make = () =>
  <RadioGroup defaultValue="option2" className="w-fit">

Invalid

Use aria-invalid on RadioGroupItem and data-invalid on Field to show validation errors.

@react.component
let make = () =>
  <Field.Set className="w-full max-w-xs">

API Reference

See the Base UI Radio Group documentation.