Skip to content

CdsButtonToggle

New in v4.0

A toggle group turns CdsButton into a switch: the pressed button stays selected, and the choice is available through v-model. Use it for modes and filters that are visible right away — the layout of a list, the period of a report, formatting options.

Storybook GitLab Figma
Test coverage: 79% — partial coverage
API in specs
19 / 24 props, events, slots and exposed members with a test
Test cases
24 unit · 0 browser
Code coverage
100% lines · 100% branches measured in v4.0.0-alpha.13
A11y (axe)
2 recommendations in 10 stories measured in v4.0.0-alpha.11

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

NameTypeDefaultDescription
activeColorstring | 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
baseColorstring | 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.
disabledboolean | null | undefinednullDisabled state
dividedboolean | undefined—Adds dividers between the buttons of the group.
mandatoryboolean | "force" | undefined—Requires at least one item to stay selected
maxnumber | undefined—Maximum number of items that can be selected
modelValueany—Value of the selected items of the group
multipleboolean | undefined—Allows selecting several items at once
requiredboolean | "force" | undefined—Requires at least one item to stay selected
selectedClassstring | undefined—CSS class applied in the selected state
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
themestring | undefined—Component theme
variant"solid" | "soft" | "outline" | "surface" | "ghost" | undefined'soft'Buttons variant: solid, soft, outline, surface, ghost

Events

NameTypeDescription
update:modelValue[value: unknown]Fires when the selected value changes.

Slots

NameTypeDescription
defaultCdsButtonToggleSlotPropsButtons of the toggle group. The slot props expose the state of the group (selection, navigation).

Exposed

NameTypeDescription
isSelected(id: string) => booleanChecks whether the button with this id is selected
next() => voidSelects the next button
prev() => voidSelects the previous button
select(id: string, value: boolean) => voidSelects a button by its id
selectedreadonly string[]Ids of the selected buttons