[ 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.
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.
<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).
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.
<RadioGroup color="success" defaultValue="on-track" options={statusOptions} />
<RadioGroup color="danger" defaultValue="blocked" options={statusOptions} />Horizontal#
<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 />
| Prop | Type | Default | Description |
|---|---|---|---|
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>. |
name | string | auto | Shared input name. Generated automatically if omitted. |
orientation | 'vertical' | 'horizontal' | 'vertical' | Layout direction. |
color | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'primary' | Selected dot and focus ring color for every option. |
disabled | boolean | false | Disables the whole group. |
options*-{ label: ReactNode; value: string; description?: ReactNode; disabled?: boolean }[]The choices to render.
value-stringSelected value (controlled).
defaultValue-stringInitially selected value (uncontrolled).
onChange-(value: string) => voidCalled with the newly selected value.
label-ReactNodeGroup label, rendered as a <legend>.
nameautostringShared 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.
disabledfalsebooleanDisables the whole group.
<Radio />
Accepts native radio attributes and forwards its ref.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | - | Clickable label. |
description | ReactNode | - | Secondary text below the label. |
color | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'primary' | Selected dot and focus ring color. |
label-ReactNodeClickable label.
description-ReactNodeSecondary 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.