Skip to content

Radio Group

Download .md

A radio group shows two to five options at once and lets people pick exactly one.

  • Use it for 2 to 5 options that people should compare before picking, such as the type of a release.
  • Use a Select for more options, and a Switch or Checkbox for one yes-or-no setting.
  • Always pick a sensible default.
React
Jenis rilis

Satu sampai tiga lagu.

Empat sampai enam lagu.

Tujuh lagu atau lebih.

Vue
Jenis rilis

Satu sampai tiga lagu.

Empat sampai enam lagu.

Tujuh lagu atau lebih.

123
  1. 1Option
  2. 2Selected option
  3. 3Label

A FieldSet with a FieldLegend that asks the question, and one row per option: a round item on an input border that fills with primary when chosen, its label and an optional one-sentence description.

There is one style.

React Vue Flutter Type Default Use
value / defaultValue v-model / default-value initialValue text none The chosen option.
onValueChange @update:model-value onChanged function none Runs when the choice changes.
RadioGroupItem value RadioGroupItem value ShadRadio value text none One option.
label in FieldLabel label in FieldLabel label, sublabel text none Names the option.
disabled disabled enabled: false boolean false Blocks the group or one item.
import { useId } from "react"
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from "@/components/ui/field"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
const types = [
{ value: "single", label: "Single", hint: "Satu sampai tiga lagu." },
{ value: "ep", label: "EP", hint: "Empat sampai enam lagu." },
{ value: "album", label: "Album", hint: "Tujuh lagu atau lebih." },
]
export default function RadioGroupDemo() {
const id = useId()
return (
<FieldSet className="w-full max-w-sm">
<FieldLegend id={`${id}-legend`}>Jenis rilis</FieldLegend>
<RadioGroup defaultValue="single" aria-labelledby={`${id}-legend`}>
{types.map((t) => (
<Field key={t.value} orientation="horizontal">
<RadioGroupItem value={t.value} id={`${id}-${t.value}`} aria-describedby={`${id}-${t.value}-hint`} />
<FieldContent>
<FieldLabel htmlFor={`${id}-${t.value}`}>{t.label}</FieldLabel>
<FieldDescription id={`${id}-${t.value}-hint`}>{t.hint}</FieldDescription>
</FieldContent>
</Field>
))}
</RadioGroup>
</FieldSet>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/radio-group.json
  • The group has role="radiogroup", named by its legend; each option has role="radio".
  • Tab moves into the group to the chosen option; the arrow keys move the choice.
  • Tie each description to its option with aria-describedby.