Pick one
type=single: one item is on, clicking it again clears it. Joined outline items share one box; the seam between two items is a short pencil stroke at the edge they share.
A row of toggles that belong together: pick one (alignment) or several (bold, italic, underline). Joined outline items share one hand-drawn box with a pencil seam between them; the highlighter body marks what is on.
npx shadcn@latest add @wobko/toggle-group第一次使用?先把 registry 加进 components.json。 如何安装
type=single: one item is on, clicking it again clears it. Joined outline items share one box; the seam between two items is a short pencil stroke at the edge they share.
type=multiple: any of the items can be on at once, and each one knows its own state. Icon items need names; hand-lettered items are just text in the script font. The sample line follows the group.
Outline items that touch share one box. Give them spacing and each keeps its own. Borderless items only whisper their seams. Vertical groups stack and use the up and down arrows.
The group in a card header, driving what the card shows. Every item has a name; the current view is also written out in the description.
A group of days inside a Field keeps the width of its buttons, and `aria-invalid` (a Form's FormControl sets it) draws the one shared box in red pencil, like any invalid field. Pick a day and it turns back to ink.
Official `toggle-group-demo`: three outline toggles, any number of them on (`type="multiple"`). Joined outline items share one felt-tip box with a drawn seam between them. One label differs from the original, which calls the underline "strikethrough".
Official `toggle-group-disabled`: `disabled` on the group disables every item. The items are drawn as dashed pencil gray, and none of them can be focused or toggled.
Official `toggle-group-lg`: `size="lg"` on the group sizes every item. The default variant has no box, so the items are only seams and a highlighter body when on.
Official `toggle-group-outline`: `variant="outline"` with `type="multiple"`. The group draws one box around all its items, so the three read as a single control.
Official `toggle-group-sm`: `size="sm"` with `type="single"`, so turning one on turns the others off. Arrow keys move between items and the group is one tab stop.
Official `toggle-group-single`: `type="single"`, at most one item on; pressing the one that is on turns it off again, so the group can also hold nothing.
Official `toggle-group-spacing`: `spacing={2}` pulls the items apart, so each keeps a box of its own. shadcn fills the icon with a color when an item is on; here each item keeps its highlighter body and writes its icon in that color instead (a drawn line has no fill to change).
A Radix ToggleGroup (single: a radio group; multiple: a toolbar). With variant outline and spacing 0 the group is the ink host and draws the one box around every item; otherwise the items draw themselves. It passes variant, size, spacing and tone down to its items.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| type | "single" | "multiple" | - | single = at most one item is on (radio semantics); multiple = any number (aria-pressed buttons). |
| variant | "default" | "outline" | "default" | Same as Toggle. |
| size | "default" | "sm" | "lg" | "default" | Same as Toggle. |
| aria-invalid | boolean | - | Marks the choice as wrong (a Form's `FormControl` sets it). The shared box of an outline group turns red pencil; separate toggles each draw a red box. An item's own `aria-invalid={false}` wins; a disabled group stays graphite. Put the group in a `Field` and it keeps the width of its buttons (a vertical Field stretches every other child). |
| spacing | number | 0 | Gap between items in the spacing scale (4 px units). 0 joins them: outline items share one box and the seams between them. |
| tone | "hi" | "marker" | "hi" | The color of an item's body when it is on. |
| orientation | "horizontal" | "vertical" | - | Vertical stacks the items, stretches them to one width, and moves the roving focus to the up and down arrows. |
| value / defaultValue / onValueChange | Radix | - | Controlled and uncontrolled state: a string for single, a string[] for multiple. |
| disabled | boolean | false | Disables every item; the joined box turns into a dashed pencil box. |
| seed | string | number | - | Pins the hand of the group's box. |
A Radix ToggleGroup item: a toggle that reads variant and size from its group. In a joined group it draws only its seam (at the edge it shares with the item before it), its body and its focus ring.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value | string | - | The item's value in the group. |
| variant / size | as Toggle | - | Used only when the group does not set them. An item that asks for outline in a group with no variant draws a box of its own (the group draws none); only a group with variant outline and spacing 0 shares one box. |
| asChild | boolean | false | Render your own element (Radix Slot). |
| seed | string | number | - | Pins the hand of this item. |
CLI 会复制进你项目的文件。
正在加载源码