Appearance
ToggleGroup
A group of toggle buttons that tracks which item(s) are pressed. By default it is single-select (like a radio group); add multiple to let several items be pressed at once. Add borders for a framed segmented control that looks like a ButtonGroup. Built on reka-ui's ToggleGroup.
Examples
Single select
v-model holds the pressed value (a string). Clicking the active item again clears the selection.
Interval
Selected: weekly
vue
<script setup>
import { ref } from "vue";
const interval = ref("weekly");
</script>
<ToggleGroup
v-model="interval"
label="Interval"
hint="How often the model reports"
:options="[
{ value: 'daily', label: 'Daily' },
{ value: 'weekly', label: 'Weekly' },
{ value: 'monthly', label: 'Monthly' },
]"
/>Required
Add required when one item must always be pressed, as with a view switcher. Clicking the active item leaves it pressed. In multiple mode the last pressed item cannot be cleared.
Selected: chart
vue
<ToggleGroup
v-model="view"
required
aria-label="View"
:options="[
{ value: 'chart', label: 'Chart' },
{ value: 'table', label: 'Table' },
]"
/>Multiple select
With multiple, v-model is a string[] and any number of items can be pressed at once.
Active days
Selected: mon, wed
vue
<script setup>
import { ref } from "vue";
const days = ref(["mon", "wed"]);
</script>
<ToggleGroup
v-model="days"
multiple
label="Active days"
:options="[
{ value: 'mon', label: 'Mon' },
{ value: 'tue', label: 'Tue' },
{ value: 'wed', label: 'Wed' },
{ value: 'thu', label: 'Thu' },
{ value: 'fri', label: 'Fri' },
]"
/>Variants
variant paints the pressed item with the same palette as Button: primary (default, a solid primary fill), secondary (a primary outline) or neutral (a light grey fill).
vue
<ToggleGroup v-model="value" aria-label="Primary" :options="options" />
<ToggleGroup
v-model="value"
variant="secondary"
aria-label="Secondary"
:options="options"
/>
<ToggleGroup
v-model="value"
variant="neutral"
aria-label="Neutral"
:options="options"
/>Borders
borders frames the group and draws dividers between the items. The pressed item is a solid primary fill for primary, a primary tint for secondary and the lighter, outlined item for neutral.
vue
<ToggleGroup
v-model="value"
borders
aria-label="Bordered primary"
:options="options"
/>
<ToggleGroup
v-model="value"
variant="secondary"
borders
aria-label="Bordered secondary"
:options="options"
/>
<ToggleGroup
v-model="value"
variant="neutral"
borders
aria-label="Bordered neutral"
:options="options"
/>Vertical and disabled options
Set orientation="vertical" to stack the items, and mark individual options disabled.
vue
<ToggleGroup
v-model="view"
orientation="vertical"
aria-label="View"
:options="[
{ value: 'map', label: 'Map' },
{ value: 'chart', label: 'Chart' },
{ value: 'table', label: 'Table', disabled: true },
]"
/>Model
| Name | Type |
|---|---|
v-model | string | string[] |
Props
| Prop | Type | Required | Default |
|---|---|---|---|
label | string | No | — |
hideLabel | boolean | No | — |
ariaLabel | string | No | — |
hint | string | No | — |
options | ToggleGroupOption[] | Yes | — |
multiple | boolean | No | — |
disabled | boolean | No | — |
required | boolean | No | — |
orientation | "horizontal" | "vertical" | No | "horizontal" |
variant | "primary" | "secondary" | "neutral" | No | "primary" |
borders | boolean | No | — |
ToggleGroupOption
ts
interface ToggleGroupOption {
value: string;
label: string;
disabled?: boolean;
}