Radio group
npx shadcn add @klarhimmel/radio-groupCopy for AIExamples
Basic
States
Form
DetailsAbout, usage, props and more
One choice from a few options that are all visible. Built on native radio inputs.
When to use
Use for
Two to five mutually exclusive options that are better seen together.
Not for
Many options. Use Select. Independent yes/no choices. Use Checkbox.
Pairs with
Field, Button, forms.
Preview
Chosen: buffet
Import
Import
- Files
- radio-group.tsx, in components/klarhimmel/ui/. With it: theme, utils.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
RadioGroup.legend | ReactNode | required | Required: the question the options answer. It names the group for assistive tech. |
RadioGroup.name | string | - | The form field name. Radios sharing a name are one group to the browser. |
RadioGroup.value | string | - | Controlled or uncontrolled state. |
RadioGroup.defaultValue | string | - | Controlled or uncontrolled state. |
RadioGroup.onValueChange | (value: string) => void | - | Controlled or uncontrolled state. |
RadioGroup.disabled | boolean | - | Helper or error text, error styling, switch the group off. |
RadioGroup.invalid | boolean | - | Helper or error text, error styling, switch the group off. |
RadioGroup.hint | ReactNode | - | Helper or error text, error styling, switch the group off. |
RadioGroup.className | string | - | Extra classes, merged after the component's own. |
RadioGroup.children | ReactNode | required | |
Radio.value | string | required | Controlled or uncontrolled state. |
Radio.label | ReactNode | required | Value and label are required; the hint sits under the label. |
Radio.hint | ReactNode | - | Helper or error text, error styling, switch the group off. |
native attributes | InputHTMLAttributes | - | Every native attribute of the element passes through, className included. |
Accessibility
| Key | Does |
|---|---|
Tab / Shift+Tab | Enters and leaves the group as one stop, landing on the chosen option |
Down / Right | Moves to the next option and selects it, wrapping |
Up / Left | Moves to the previous option and selects it, wrapping |
Space | Selects the focused option |
Native radio inputs: the browser provides the keys and the form value, also without script.
Accessibility