coss.com Svelte

Toggle Group

Provides a shared state to a series of toggle buttons.

API Reference
Loading p-toggle-group-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/toggle-group.json

Usage

<script lang="ts">
  import * as ToggleGroup from "$lib/components/ui/toggle-group/index.js";
</script>

<ToggleGroup.Root>
  <ToggleGroup.Item value="bold">Bold</ToggleGroup.Item>
  <ToggleGroup.Item value="italic">Italic</ToggleGroup.Item>
  <ToggleGroup.Item value="underline">Underline</ToggleGroup.Item>
</ToggleGroup.Root>

API Reference

ToggleGroup.Root

The root owns the selection and shares its styling and interaction state with the child toggles.

PropTypeDefaultDescription
valuereadonly string[][]Current selection; supports bind:value
defaultValuereadonly string[][]Initial selection for uncontrolled use
multiplebooleanfalseAllows more than one pressed item
orientation"horizontal" \| "vertical""horizontal"Sets the group axis and arrow-key direction
disabledbooleanfalseDisables every item in the group
loopFocusbooleantrueWraps arrow-key focus at the ends of the group
onValueChange(value: string[]) => voidRuns when the selection changes
variant"default" \| "outline""default"Controls the styling of all child toggles
size"default" \| "sm" \| "lg""default"Controls the size of all child toggles
askeyof HTMLElementTagNameMap"div"HTML element to render

ToggleGroup.Item

Each item needs a unique value. It accepts the Toggle props and inherits variant and size from the root. Arrow keys, Home, and End move focus within the group.

ToggleGroup.Separator

The separator follows the group’s orientation and preserves the connected outline treatment.

See the Shards Toggle Group API for focus and selection behavior.

Examples

Small Toggles

Loading p-toggle-group-2 preview…

Large Toggles

Loading p-toggle-group-3 preview…

With Outline Toggles

Loading p-toggle-group-4 preview…

Vertical

Loading p-toggle-group-5 preview…

Disabled

Loading p-toggle-group-6 preview…

With Disabled Toggle

Loading p-toggle-group-7 preview…

Multiple selection

Loading p-toggle-group-8 preview…

With Tooltips

Loading p-toggle-group-9 preview…

Changelog