Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- EmptyNew
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input GroupNew
- KbdNew
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- SkeletonNew
- Slider
- SpinnerNew
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Resources
Toggle Group
Provides a shared state to a series of toggle buttons.
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]}>
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
Installation
pnpm dlx shadcn@latest add @coss/toggle-group
Usage
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group"<ToggleGroup>
<Toggle>Bold</Toggle>
<Toggle>Italic</Toggle>
<Toggle>Underline</Toggle>
</ToggleGroup>Examples
Small Toggles
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]} size="sm">
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
Large Toggles
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]} size="lg">
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
With Outline Toggles
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import {
Toggle,
ToggleGroup,
ToggleGroupSeparator,
} from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]} variant="outline">
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<ToggleGroupSeparator />
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<ToggleGroupSeparator />
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
Vertical
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import {
Toggle,
ToggleGroup,
ToggleGroupSeparator,
} from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup
defaultValue={["bold"]}
orientation="vertical"
variant="outline"
>
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<ToggleGroupSeparator orientation="horizontal" />
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<ToggleGroupSeparator orientation="horizontal" />
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
Disabled
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]} disabled>
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
With Disabled Toggle
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function ParticleItem() {
return (
<ToggleGroup defaultValue={["bold"]}>
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" disabled value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
Multiple selection
import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group";
export default function Particle() {
return (
<ToggleGroup defaultValue={["bold"]} multiple>
<Toggle aria-label="Toggle bold" value="bold">
<BoldIcon />
</Toggle>
<Toggle aria-label="Toggle italic" value="italic">
<ItalicIcon />
</Toggle>
<Toggle aria-label="Toggle underline" value="underline">
<UnderlineIcon />
</Toggle>
</ToggleGroup>
);
}
With Tooltips
Component tooltip-grouped not found in registry.
Comparing with Radix / shadcn
If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with coss ui quickly.
Prop Mapping
| Component | Radix UI Prop | Base UI Prop |
|---|---|---|
ToggleGroup | type (enum, "single" or "multiple") | multiple (boolean, default: false) |
Quick Checklist
- Replace
type="multiple"→multipleonToggleGroup - Remove
type="single"fromToggleGroup - Always use arrays for
defaultValue - Use
Togglegoing forward;ToggleGroupItemremains for legacy
Additional Notes
coss ui toggle group sizes are more compact compared to shadcn/ui, making them better suited for dense applications:
| Size | Height (shadcn/ui) | Height (coss ui) |
|---|---|---|
sm | 32px | 28px |
default | 36px | 32px |
lg | - | 36px |
So, for example, if you were using the default size in shadcn/ui and you want to preserve the original height, you should use the lg size in coss ui.
Comparison Examples
<ToggleGroup type="multiple" defaultValue={["bold"]}>
<ToggleGroupItem value="bold">B</ToggleGroupItem>
<ToggleGroupItem value="italic">I</ToggleGroupItem>
<ToggleGroupItem value="underline">U</ToggleGroupItem>
</ToggleGroup><ToggleGroup multiple defaultValue={["bold"]}>
<Toggle value="bold">B</Toggle>
<Toggle value="italic">I</Toggle>
<Toggle value="underline">U</Toggle>
</ToggleGroup>