Toggle Group

Provides a shared state to a series of toggle buttons.

Loading...
Loading code...

Installation

pnpm dlx shadcn@latest add @uitopia/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

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

ComponentRadix UI PropBase UI Prop
ToggleGrouptype (enum, "single" or "multiple")multiple (boolean, default: false)

Quick Checklist

  • Replace type="multiple"multiple on ToggleGroup
  • Remove type="single" from ToggleGroup
  • Always use arrays for defaultValue
  • Use Toggle going forward; ToggleGroupItem remains for legacy

Additional Notes

ui/topia toggle group sizes are more compact compared to shadcn/ui, making them better suited for dense applications:

SizeHeight (shadcn/ui)Height (ui/topia)
sm32px28px
default36px32px
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

shadcn/ui
<ToggleGroup type="multiple" defaultValue={["bold"]}>
  <ToggleGroupItem value="bold">B</ToggleGroupItem>
  <ToggleGroupItem value="italic">I</ToggleGroupItem>
  <ToggleGroupItem value="underline">U</ToggleGroupItem>
</ToggleGroup>
ui/topia
<ToggleGroup multiple defaultValue={["bold"]}>
  <Toggle value="bold">B</Toggle>
  <Toggle value="italic">I</Toggle>
  <Toggle value="underline">U</Toggle>
</ToggleGroup>