120k

Toggle Group

A set of two-state buttons that can be toggled on or off.

Installation

pnpm dlx shadcn@latest add @force-ui-svelte/toggle-group

Usage

<script lang="ts">
  import * as ToggleGroup from "$lib/components/ui/toggle-group/index.js";
</script>
<ToggleGroup.Root type="single">
  <ToggleGroup.Item value="a">A</ToggleGroup.Item>
  <ToggleGroup.Item value="b">B</ToggleGroup.Item>
  <ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>

Composition

Use the following composition to build a ToggleGroup:

ToggleGroup.Root
├── ToggleGroup.Item
└── ToggleGroup.Item

Examples

Outline

Use variant="outline" for an outline style.

Size

Use the size prop to change the size of the toggle group.

Spacing

Use spacing={2} to add spacing between toggle group items.

Vertical

Use orientation="vertical" for vertical toggle groups.

Disabled

Custom

A custom toggle group example.

API Reference

See the Radix Toggle Group documentation.