Inputs
ToggleGroup
A set of toggle buttons with single or multiple selection, roving focus and arrow-key navigation.
<script>
import { ToggleGroup } from "@codeatlasdev/ui";
let format = $state(["bold"]);
</script>
<ToggleGroup type="multiple" aria-label="Text formatting" bind:value={format} items={items} />
In single mode the user can press the active item again to clear the selection, so value can be an empty string. Use SegmentedControl when a choice is required. Icon-only items need an aria-label.
Single and multiple
type="single" binds a string. type="multiple" binds a string array.
value: left
value: ["bold"]
Code
Variants and orientation
outlined and ghost variants, sizes, a disabled item and a vertical layout.
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'single' | 'multiple' | 'single' | Selection mode. |
value | string | string[] | – | Bindable. A string for single, an array for multiple. |
items | ToggleGroupItem[] | – | { value, label?, icon?, disabled?, 'aria-label'? }. Icon-only items need aria-label. |
size | 'sm' | 'md' | 'md' | Item height. |
variant | 'outlined' | 'ghost' | 'outlined' | Container style. |
disabled | boolean | false | Disables the whole group. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Layout and arrow-key axis. |
aria-label | string | – | Accessible name of the group. |
class | string | – | Extra classes on the root. |
onchange | (value: string | string[]) => void | – | Called on every change. |