[ Forms ]

Radio Group

RadioGroup renders a labelled set of radio buttons where exactly one can be selected. The lower-level Radio component is also exported for custom layouts.

5 examplesDark modeAccessible

Import#

import { RadioGroup, Radio } from 'reusify-ui';

When to use#

  • Picking exactly one option from 2 to 5 choices that should all be visible at once.
  • For longer lists use Select; for on/off use Switch or Checkbox.

Examples#

Basic#

Uncontrolled: set defaultValue and read the value from the form, or listen with onChange.

Delivery speed
<RadioGroup
  label="Delivery speed"
  defaultValue="standard"
  options={[
    { label: 'Standard', value: 'standard' },
    { label: 'Express', value: 'express' },
    { label: 'Overnight', value: 'overnight' },
  ]}
/>

Controlled with descriptions#

onChange receives the selected value directly (not an event).

Plan

Selected: pro

const [plan, setPlan] = useState('pro');

<RadioGroup
  label="Plan"
  value={plan}
  onChange={setPlan}
  options={[
    { label: 'Hobby', value: 'hobby', description: 'Free forever' },
    { label: 'Pro', value: 'pro', description: '₹499 / month' },
    { label: 'Enterprise', value: 'enterprise', description: 'Contact sales', disabled: true },
  ]}
/>

Colors#

color on RadioGroup applies to every option. Standalone Radio takes the same prop.

Success
Warning
Danger
<RadioGroup color="success" defaultValue="on-track" options={statusOptions} />
<RadioGroup color="danger" defaultValue="blocked" options={statusOptions} />

Horizontal#

Size
<RadioGroup
  label="Size"
  orientation="horizontal"
  defaultValue="m"
  options={[
    { label: 'S', value: 's' },
    { label: 'M', value: 'm' },
    { label: 'L', value: 'l' },
    { label: 'XL', value: 'xl' },
  ]}
/>

Standalone Radio#

Build your own layout with Radio. Give each one the same name.

<Radio name="theme" value="light" label="Light" defaultChecked />
<Radio name="theme" value="dark" label="Dark" />

API reference#

<RadioGroup />

options*-
{ label: ReactNode; value: string; description?: ReactNode; disabled?: boolean }[]

The choices to render.

value-
string

Selected value (controlled).

defaultValue-
string

Initially selected value (uncontrolled).

onChange-
(value: string) => void

Called with the newly selected value.

label-
ReactNode

Group label, rendered as a <legend>.

nameauto
string

Shared input name. Generated automatically if omitted.

orientation'vertical'
'vertical' | 'horizontal'

Layout direction.

color'primary'
'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info'

Selected dot and focus ring color for every option.

disabledfalse
boolean

Disables the whole group.

<Radio />

Accepts native radio attributes and forwards its ref.

label-
ReactNode

Clickable label.

description-
ReactNode

Secondary text below the label.

color'primary'
'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info'

Selected dot and focus ring color.

Accessibility#

  • Wrapped in a <fieldset> with a <legend>, so the group label is announced.
  • Native radios: Tab moves into the group, arrow keys move between options.