ToggleGroup
ActionsA set of joined toggles: <ToggleGroup.Root> (type="single" or "multiple", bind:value, variant, size) holds ToggleGroup.Items (value). Arrow keys move between items; Space or Enter presses one. Name the group with aria-label.
import { ToggleGroup } from '@limerdev/zest'; Use for
Picking one or several of a few view options shown at once: alignment, a chart's period (day, week, month), which columns to show.
Don't
A choice in a form: use
RadioGroup or Checkboxes. Switching views of a page's content: use Tabs.Examples
Basic
type="single" picks one period; type="multiple" shows several columns.
Per week, showing hours
<script lang="ts">
import { ToggleGroup } from '@limerdev/zest';
let period = $state('week');
let columns: string[] = $state(['hours']);
</script>
<div class="flex flex-col items-center gap-4">
<ToggleGroup.Root type="single" bind:value={period} variant="outline" aria-label="Period">
<ToggleGroup.Item value="day">Day</ToggleGroup.Item>
<ToggleGroup.Item value="week">Week</ToggleGroup.Item>
<ToggleGroup.Item value="month">Month</ToggleGroup.Item>
</ToggleGroup.Root>
<ToggleGroup.Root type="multiple" bind:value={columns} size="sm" aria-label="Columns">
<ToggleGroup.Item value="hours">Hours</ToggleGroup.Item>
<ToggleGroup.Item value="cost">Cost</ToggleGroup.Item>
<ToggleGroup.Item value="margin">Margin</ToggleGroup.Item>
</ToggleGroup.Root>
<p class="text-sm text-muted">Per {period}, showing {columns.join(', ') || 'nothing'}</p>
</div> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
ToggleGroup.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the toggle group is disabled or not. |
| loop | boolean | true | Whether to loop through the items when reaching the end when using the keyboard. |
| onValueChange | OnChangeFn<string> | OnChangeFn<string[]> | – | |
| orientation | "horizontal" | "vertical" | 'horizontal' | The orientation of the toggle group. Used to handle keyboard navigation between items. |
| rovingFocus | boolean | – | Whether to enable roving focus or not. When enabled, users navigate between the items using the arrow keys. When disabled, users navigate between the items using the tab key. |
| size | "default" | "sm" | "lg" | 'default' | The height and padding, from the theme's field size. |
| type required | "multiple" | "single" | – | |
| value bindable | string | string[] | – | |
| variant | "outline" | "default" | 'default' | default is plain until pressed; outline has a border. |
ToggleGroup.Item
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | null | false | true | false | Whether the toggle item is disabled or not. |
| value required | string | – | The value of the toggle item. |