Toggle Group
Provides a shared state to a series of toggle buttons.
Loading...
Loading code...
Installation
Usage
import { Toggle, ToggleGroup } from "@/components/ui/toggle-group"<ToggleGroup>
<Toggle>Bold</Toggle>
<Toggle>Italic</Toggle>
<Toggle>Underline</Toggle>
</ToggleGroup>Examples
Small Toggles
Loading...
Loading code...
Large Toggles
Loading...
Loading code...
With Outline Toggles
Loading...
Loading code...
With Outline and Separator
Loading...
Loading code...
Disabled
Loading...
Loading code...
With Disabled Toggle
Loading...
Loading code...
Multiple selection
Loading...
Loading code...
With Tooltips
Loading...
Loading code...
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 ui/topia 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
ui/topia toggle group sizes are more compact compared to shadcn/ui, making them better suited for dense applications:
| Size | Height (shadcn/ui) | Height (ui/topia) |
|---|---|---|
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 ui/topia.
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>