If the buttons trigger actions instead of storing a choice, take CdsButtonGroup. To pick from a long list use CdsSelect, and inside forms — CdsRadioGroup.
Variations
Selection
By default a single button is selected, and clicking it again clears the choice. v-model receives the value of the button, or its index when no value is set.
Multiple selection
The multiple prop allows selecting several buttons — v-model becomes an array of values.
The max prop limits the number of selected buttons: once the limit is reached, clicks on the remaining buttons add nothing to the selection.
Mandatory selection
The mandatory prop keeps the last choice from being cleared — the group always stays in some state. With the 'force' value the first available button is selected automatically, even when v-model is empty.
Color of the active button
The active-color prop repaints the selected buttons — the choice stands out on panels crowded with controls.
Group props
CdsButtonToggle is built on CdsButtonGroup and accepts all of its props: variant and size apply to every button at once, and the default variant is soft. active-color or color set the color of the selected button (brand by default), base-color the unselected ones (neutral by default); divided adds dividers, and direction="vertical" turns the group into a column.
Guidelines
Scenarios
View mode
The classic toggle group — switching between a list and a grid. Icon buttons with aria-label save space, mandatory guarantees that the list is always shown in one of the modes, and the neutral default look with size="sm" keeps the control from stealing attention from the content.
Formatting toolbar
Text styles are independent of each other, so the group works with multiple: each button turns its own style on and off, and v-model collects the selected values into an array.
Period filter
Give the buttons a value — and v-model returns a meaningful value to query the data with. mandatory keeps the user from ending up without a period: the numbers always belong to the selected range.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
activeColor | string | undefined | — | Color of the component in its active state |
appearancedeprecated | "inverse" | "primary" | "secondary" | "tertiary" | "transparent" | undefined | — | Visual appearance of the component. Deprecated: use variant and color |
baseColor | string | undefined | — | Color of the component in its inactive state |
color | (string & {}) | "neutral" | "brand" | "accent" | "danger" | "inverse" | undefined | 'brand' | Component color: a role, a palette alias, a theme token or a CSS color |
direction | "horizontal" | "vertical" | undefined | 'horizontal' | Switches the component between horizontal and vertical layout. |
disabled | boolean | null | undefined | null | Disabled state |
divided | boolean | undefined | — | Adds dividers between the buttons of the group. |
mandatory | boolean | "force" | undefined | — | Requires at least one item to stay selected |
max | number | undefined | — | Maximum number of items that can be selected |
modelValue | any | — | Value of the selected items of the group |
multiple | boolean | undefined | — | Allows selecting several items at once |
required | boolean | "force" | undefined | — | Requires at least one item to stay selected |
selectedClass | string | undefined | — | CSS class applied in the selected state |
size | number | "xs" | "sm" | "md" | "lg" | "xl" | undefined | 'md' | Size of the component |
tag | string | JSXComponent<any> | undefined | 'div' | Custom HTML tag or component to render |
theme | string | undefined | — | Component theme |
variant | "solid" | "soft" | "outline" | "surface" | "ghost" | undefined | 'soft' | Buttons variant: solid, soft, outline, surface, ghost |
Events
| Name | Type | Description |
|---|---|---|
update:modelValue | [value: unknown] | Fires when the selected value changes. |
Slots
| Name | Type | Description |
|---|---|---|
default | CdsButtonToggleSlotProps | Buttons of the toggle group. The slot props expose the state of the group (selection, navigation). |
Exposed
| Name | Type | Description |
|---|---|---|
isSelected | (id: string) => boolean | Checks whether the button with this id is selected |
next | () => void | Selects the next button |
prev | () => void | Selects the previous button |
select | (id: string, value: boolean) => void | Selects a button by its id |
selected | readonly string[] | Ids of the selected buttons |