Default
Pick one. The choice is circled, then colored in: a terracotta blot with a felt spiral written into it. Arrow keys move the choice.
Pick exactly one. Each choice is a hand-circled ring; picking it colors the dot in with a terracotta blot and writes a felt spiral into it. Radix Radio Group underneath: roving focus, arrow keys, form value, orientation and direction.
npx shadcn@latest add @wobko/radio-group第一次使用?先把 registry 加进 components.json。 如何安装
Pick one. The choice is circled, then colored in: a terracotta blot with a felt spiral written into it. Arrow keys move the choice.
16, 20 and 28 px; off, on, invalid (red pencil, still red on top of the dot) and disabled (dashed, graphite dot). A horizontal group lays its radios in a row.
Radios with a title and a line of help, and a second horizontal group for billing. Hovering the row lights its radio; the description hangs off the label with aria-describedby.
`name` on the group puts the chosen value in FormData (Radix keeps hidden native radios in sync) and `required` blocks the submit until one is picked.
Official `radio-group-demo`: three options, the middle one chosen. Click, or focus the group and use the arrow keys; the chosen ring gets its dot written in. Only change: the ids are prefixed to stay unique on a page with other examples.
The root (Radix RadioGroup, role=radiogroup): a grid with a gap; `orientation="horizontal"` lays it out as a wrapping row.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value / defaultValue / onValueChange | string / string / (value: string) => void | - | Controlled or uncontrolled selection. |
| name / required / disabled / form | string | boolean | - | Forwarded to Radix's hidden native radios, so the value is in FormData and `required` blocks the submit. A form reset puts the group back to its `defaultValue`. `disabled` on the group draws every radio disabled. |
| aria-invalid | boolean | "true" | "false" | - | On the group (where FormControl puts it) every radio is drawn in red pencil; a radio can still set its own aria-invalid. |
| orientation | "horizontal" | "vertical" | - | Arrow-key axis (and, here, the layout). Radix arrows work on both axes either way. |
| dir | "ltr" | "rtl" | - | Direction for the arrow keys. |
| loop | boolean | true | Arrow keys wrap around. |
Radix RadioGroup.Item (a <button role="radio">, plus a hidden input inside a form) with the ring drawn behind it. Size it with size-*: 16, 20 and 28 px are drawn and tested. The spiral is written with ll-draw when the state turns checked after a touch (instantly with reduced motion; never at load).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value | string | - | The value the group takes when this radio is chosen. |
| disabled | boolean | false | Dashed pencil ring on a graphite wash, graphite dot when chosen. Not focusable. |
| aria-invalid | boolean | "true" | "false" | - | true draws the ring in red pencil, and keeps it red over the dot. |
| seed | string | number | - | Pins the hand: the same seed always draws the same ring and dot. Default: derived from useId(). |
CLI 会复制进你项目的文件。
正在加载源码