Skip to content
Actions Core Stable

ToggleGroup

.md

A segmented row of toggle buttons with roving-tabindex keyboard navigation and single or multiple selection.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { ToggleGroup } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { ToggleGroup, ToggleGroupItem } from "fancy-ui-svelte";

	let alignment = $state("left");
</script>

<ToggleGroup sound bind:value={alignment} label="Text alignment">
	<ToggleGroupItem value="left" label="Align left">
		<svg
			class="size-4"
			viewBox="0 0 24 24"
			fill="none"
			stroke="currentColor"
			stroke-width="2"
			stroke-linecap="round"
			aria-hidden="true"
		>
			<line x1="3" y1="6" x2="21" y2="6" />
			<line x1="3" y1="12" x2="15" y2="12" />
			<line x1="3" y1="18" x2="18" y2="18" />
		</svg>
	</ToggleGroupItem>
	<ToggleGroupItem value="center" label="Align center">
		<svg
			class="size-4"
			viewBox="0 0 24 24"
			fill="none"
			stroke="currentColor"
			stroke-width="2"
			stroke-linecap="round"
			aria-hidden="true"
		>
			<line x1="3" y1="6" x2="21" y2="6" />
			<line x1="6" y1="12" x2="18" y2="12" />
			<line x1="4" y1="18" x2="20" y2="18" />
		</svg>
	</ToggleGroupItem>
	<ToggleGroupItem value="right" label="Align right">
		<svg
			class="size-4"
			viewBox="0 0 24 24"
			fill="none"
			stroke="currentColor"
			stroke-width="2"
			stroke-linecap="round"
			aria-hidden="true"
		>
			<line x1="3" y1="6" x2="21" y2="6" />
			<line x1="9" y1="12" x2="21" y2="12" />
			<line x1="6" y1="18" x2="21" y2="18" />
		</svg>
	</ToggleGroupItem>
</ToggleGroup>

Examples

Basic Usage

Single Selection

Activating the active item again clears it.

Multiple Selection

Independent on/off marks with type="multiple".

Vertical

A vertical rail — both arrow-key pairs still work.

Disabled Items

One item unavailable; the keyboard model skips it.

Props

PropTypeDefaultDescription
type "single" | "multiple""single"Whether one item can be active at a time, or several.
value string | string[]""The active value(s), bindable — a string when type="single", an array of strings when type="multiple".
onValueChange (value: string | string[]) => void-Called with the new value, shaped to match `type`, whenever the selection changes.
disabled booleanfalseDisables every item in the group.
size "sm" | "md" | "lg""md"Sizes every item.
orientation "horizontal" | "vertical""horizontal"The rail's stacking axis; both arrow-key pairs work either way.
label string-Accessible name for the group.
class string-Additional CSS classes, merged onto the root.
ref HTMLDivElement | nullnullBindable reference to the root element.
sound booleanfalsePlays toggle-on/toggle-off on a multi-select item or select on a single-select change, once the user has enabled sound
ToggleGroupItem.value *string-The item's value — what gets added to or removed from the group's selection.
ToggleGroupItem.disabled booleanfalseDisables just this item, independent of the group's own `disabled`.
ToggleGroupItem.label string-Accessible name for icon-only content on this item. Also the text fallback.
ToggleGroupItem.class string-Additional CSS classes, merged onto the item's button.
ToggleGroupItem.ref HTMLButtonElement | nullnullBindable reference to the item's button element.

Slots

SlotDescription
children The ToggleGroup's content — the ToggleGroupItems.
ToggleGroupItem.children The item's content, typically a glyph or a short label.