Skip to main content

Components

ToggleGroup

ToggleGroup groups related options. The component consists of a group of buttons that are connected, where only one button can be selected at a time.

variant
Description

Specify which variant to use

Type
"primary" | "secondary"
Default
primary
value
Description

Controlled state for `ToggleGroup` component.

Type
string
defaultValue
Description

Default value.

Type
string
onChange
Description

Callback with selected `ToggleGroupItem` `value`

Type
((value: string) => void)
name
Description

Form element name

Type
string
NameTypeDefaultDescription
variant"primary" | "secondary"primary

Specify which variant to use

valuestring-

Controlled state for `ToggleGroup` component.

defaultValuestring-

Default value.

onChange((value: string) => void)-

Callback with selected `ToggleGroupItem` `value`

namestring-

Form element name

ToggleGroupItem

value
Description

The value of the ToggleGroupItem. Generates a random value if not set.

Type
string
type
Description

Specify the type of button. Unset when `asChild` is true

Type
"submit" | "reset" | "button"
Default
'button'
icon
Description

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

Type
boolean
Default
false
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
valuestring-

The value of the ToggleGroupItem. Generates a random value if not set.

type"submit" | "reset" | "button"'button'

Specify the type of button. Unset when `asChild` is true

iconbooleanfalse

Toggle icon only styling, pass icon as children When combined with loading, the loading-icon will be shown instead of the icon.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

Usage

Examples

Icons only

Use Tooltip to explain the actions when using only icons.

Controlled

Secondary variant

HTML

JavaScript is also needed to handle focus. You can read about what you need to do to implement this in the accessibility documentation.

The class name ds-toggle-group is placed on a <div> with role="radiogroup".

Each button in the group is a <button> with class name ds-button with role="radio" and aria-checked which indicates whether the button is selected or not. data-variant for selected buttons should match data-variant on ToggleGroup. The remaining buttons should have data-variant="tertiary".

CSS variables and data attributes

CSS Variables
NameValue
--dsc-togglegroup-backgroundvar(--ds-color-surface-default)
--dsc-togglegroup-border-widthvar(--ds-border-width-default)
--dsc-togglegroup-border-stylesolid
--dsc-togglegroup-border-colorvar(--ds-color-border-default)
--dsc-togglegroup-text-colorvar(--ds-color-text-default)
--dsc-togglegroup-spacing0
--dsc-togglegroup-border-radiusvar(--ds-border-radius-default)
--dsc-togglegroup-button-sizevar(--ds-size-12)
--dsc-button-colorvar(--ds-color-text-default)
--dsc-button-color--hovervar(--ds-color-text-default)
--dsc-button-border-colorvar(--ds-color-text-default)
Data Attributes
NameValue
data-variantsecondary
data-icon
Edit this page on github.com (opens in a new tab)