Components
Toggle Group
A row of toggles, like bold and italic.
<ToggleGroup label="Text format" items={items} />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/toggle-group.jsonimport { ToggleGroup } from "@/components/toggle-group"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A row of toggle buttons, like bold, italic and underline. With multiple off, pressing one releases the others, for choices like text alignment.
import { HugeiconsIcon } from "@hugeicons/react";
import { TextBoldIcon, TextItalicIcon } from "@hugeicons/core-free-icons";
import { ToggleGroup } from "@/components/toggle-group";
const items = [
{ value: "bold", label: "Bold", icon: <HugeiconsIcon icon={TextBoldIcon} size={18} /> },
{ value: "italic", label: "Italic", icon: <HugeiconsIcon icon={TextItalicIcon} size={18} /> },
];
export function Toolbar() {
return <ToggleGroup label="Text format" items={items} onChange={(v) => console.log(v)} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | Names the group. | |
items | { value, label, icon? }[] | The buttons. With an icon, the label becomes the accessible name. | |
multiple | boolean | true | Allow several on at once. |
defaultValue | string[] | [] | On at the start. |
onChange | (value: string[]) => void | Called with every change. | |
className | string | Classes for the wrapper. |
With reduced motion, buttons change without a transition.