Skip to Content
Getting startedFoundationsComponentsPackagesTools

RadioGroup

One choice from a set, as a group with its question.

Examples

Playground

Size

States

The group in each state. An option can be disabled on its own (Extra large).

rest
Size
focus
Size
error
Size
Choose a size to continue.

Arrows move the selection

Tab into the group, then use the arrow keys. The group is one tab stop and the arrows change the selection, which comes free from native inputs sharing a name. Disabled options are skipped.

Size

Orientation

Vertical by default; horizontal for two or three short options.

vertical
Size
horizontal
Size

Install

npx shadcn add @hipuku/radio-group

Usage

import { RadioGroup } from '@/components/haus/components/Radio'

<RadioGroup
  label="Plan"
  name="plan"
  value={plan}
  onChange={setPlan}
  options={[
    { label: 'Free', value: 'free' },
    { label: 'Team', value: 'team', hint: 'Up to 20 people' },
  ]}
/>

API

RadioGroup also takes its element's own attributes and forwards its ref. className lands on the root.

PropTypeDescription
onChange((value: string, event: React.ChangeEvent<HTMLInputElement>) => void)(value, event), matching Checkbox and Toggle. The value first because a group has no single control and the value is the whole point; the event second so event.target.name is reachable.
namerequiredstring
valuestring
defaultValuestring
optionsrequiredRadioOption[]
labelstring
errorstring
requiredboolean
orientation"horizontal" | "vertical"

Options

Options come from options, not from children. Each has a label, a value, and an optional hint and disabled. orientation="horizontal" lays them in a row. onChange gives you (value, event), and it is uncontrolled unless you pass value.

Accessibility

  • One tab stop for the whole group. The arrow keys move the selection.
  • Announced as a group named by label, so the question is read before the options.
  • required and error set aria-required and aria-invalid on the group, and an error is announced when it appears.

On this page