# ToggleGroup

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

- Package: `fancy-ui-vue` (Vue 3.5+ + Tailwind CSS v4)
- Category: Actions
- Tags: toggle, segmented-control, roving-tabindex, compound, selection, toolbar
- Types: `ToggleGroupProps`, `ToggleGroupItemProps`, `ToggleGroupContext`
- Docs: https://fancy-ui.rama.app/docs/components/toggle-group
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/vue/src/components/toggle-group

## Import

```vue
<script setup lang="ts">
import { ToggleGroup } from 'fancy-ui-vue';
</script>
```

Setup (once per project): `npm install fancy-ui-vue`, then put these lines in your main CSS file (the stylesheet imports go right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-vue/tailwind.css";
@import "fancy-ui-vue/styles.css";
```

Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in a Vue template; when one differs from the Svelte name, the Svelte name follows in parentheses. Snippets become named slots (`#default` is the default snippet), a prop the Vue port declares as a model is a `v-model:<name>` (except `ref`, exposed via `defineExpose({ ref })`: put a template ref on the component and read `.ref`) and callbacks are listeners (`onclick` is `@click`). Every component sets `inheritAttrs: false`: `class` is a declared prop, merged where the Svelte component applies it (not always the root element), and only when the props table below lists it; other attributes do not fall through unless the package README lists the component as forwarding native attributes. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/vue#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `type` | `"single" \| "multiple"` | `"single"` | Whether one item can be active at a time, or several. |
| `v-model:value` (Svelte `value`) | `string \| string[]` | `""` | The active value(s), bindable — a string when type="single", an array of strings when type="multiple". |
| `@value-change` (Svelte `onValueChange`) | `(value: string \| string[]) => void` | — | Called with the new value, shaped to match `type`, whenever the selection changes. |
| `disabled` | `boolean` | `false` | Disables 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 \| null` | `null` | Bindable reference to the root element. |
| `sound` | `boolean` | `false` | Plays toggle-on/toggle-off on a multi-select item or select on a single-select change, once the user has enabled sound |
| `ToggleGroupItem.value` (required) | `string` | — | The item's value — what gets added to or removed from the group's selection. |
| `ToggleGroupItem.disabled` | `boolean` | `false` | Disables 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 \| null` | `null` | Bindable reference to the item's button element. |

## Slots

| Slot | Description |
| --- | --- |
| `#default` (Svelte `children`) | The ToggleGroup's content — the ToggleGroupItems. |
| `ToggleGroupItem.#default` (Svelte `ToggleGroupItem.children`) | The item's content, typically a glyph or a short label. |

## Example

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ToggleGroup, ToggleGroupItem } from "fancy-ui-vue";

const alignment = ref<string | string[]>("left");
</script>

<template>
	<ToggleGroup v-model:value="alignment" sound 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>
</template>
```
