A set of options where only one can be selected.
$ pnpm dlx shadcn@latest add https://dashral.com/r/radio-group.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/radio-group.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/radio-groupUsage
import { RadioGroup } from "@/components/dashral/radio-group"
<RadioGroup
label="Plan"
defaultValue="team"
options={[
{ value: "personal", label: "Personal", description: "1 developer" },
{ value: "team", label: "Team", description: "Up to 5 developers" },
]}
/>Examples
API reference
RadioGroup
Also takes every prop of Radix Radio Group(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
value / defaultValue | string | — |
onValueChange | (value: string) => voidCalled with the new value. | — |
options | (string | { value; label?; description?; icon?; disabled? })[]The radios. Required; icon shows on cards. | — |
variant | "default" | "cards"cards draws each option as a bordered card you click anywhere on. | "default" |
indicator | booleanWith cards: false hides the radio dot; the border shows what's picked. | true |
orientation | "horizontal" | "vertical"Which arrow keys move. | — |
color | "primary" | "neutral" | "info" | "success" | "warning" | "destructive" | "highlight"The color of every picked radio. | "primary" |
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
classNames | { root, label, description, error, group, item, radio }Classes for each part. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Move into the group (to the picked item) |
| Arrow keys | Move and pick |
| Space | Pick the focused item |
Accessibility
- role="radiogroup" with role="radio" items. Label the group and each item.
- label names the group through aria-labelledby; each item's label and description are linked to its radio.
Motion
- The dot springs in when an item is picked.