Create

Form

Toggle Group

Copy page View as Markdown Open in ChatGPT Open in Claude

A set of two-state buttons that can be toggled on or off.

Usage#

app.component.ts
import { WDS_TOGGLE } from '@wds/angular/toggle';

Put Toggle elements with a value in the group. The group sets their variant, size and pressed; read the choice from value (type="single") or values (type="multiple") and the wds-change event. Name the group with aria-label.

Examples#

Default#

type="multiple": any number of toggles can be pressed. values lists them, e.g. values="bold,italic".

Outline#

variant="outline" joins the toggles into one bordered control.

Single#

type="single": pressing a toggle releases the others; value holds the pressed one. A click on the pressed toggle releases it.

Segmented#

required keeps one toggle pressed (a click on the pressed one does nothing), which makes a segmented control, e.g. for a time range.

Day Week Month Year

Size#

size (sm, default, lg) applies to every toggle in the group.

Spacing#

spacing separates the toggles with a gap (--wds-toggle-group-spacing, default 4px) instead of joining them.

Star Heart Bookmark

Vertical#

orientation="vertical" stacks the toggles; Up and Down move focus.

Disabled#

disabled turns all the toggles off.

API References#

wds-toggle-group#

A set of wds-toggle buttons. With type="single" at most one is pressed (value), with type="multiple" any number (values). Arrow keys move focus between the toggles, so the group is one Tab stop.

Attributes

AttributeTypeDefaultDescription
typeWdsToggleGroupType'single'single: at most one toggle pressed; multiple: any number.
valuestring''Pressed value with type="single" ('': none).
valuesstring[][]Pressed values with type="multiple". The attribute takes a list: values="bold,italic".
variantWdsToggleVariant'default'Variant of all the toggles.
sizeWdsToggleSize'default'Size of all the toggles.
orientationWdsToggleGroupOrientation'horizontal'Layout and arrow keys: in a row (Left/Right) or in a column (Up/Down).
spacingbooleanfalseSeparates the toggles with a gap (--wds-toggle-group-spacing, default 4px) instead of joining them.
requiredbooleanfalseWith type="single", a click on the pressed toggle does not release it, so one value is always set.
disabledbooleanfalseDisables all the toggles.

Events

EventDescription
wds-changeCustomEvent<WdsToggleGroupChangeDetail>The user pressed or released a toggle.

Slots

SlotDescription
(default)wds-toggle elements, each with a value.

CSS custom properties

PropertyDescription
--wds-toggle-group-spacingGap between the toggles when spacing is set.

wds-toggle#

A two-state button that can be either on or off (aria-pressed), such as Bold in a text toolbar. In a wds-toggle-group the group decides which toggles are pressed and fires wds-change itself.

Attributes

AttributeTypeDefaultDescription
pressedbooleanfalseWhether the toggle is on.
disabledbooleanfalseDisables the toggle.
variantWdsToggleVariant'default'outline adds a border. In a group the group's variant wins.
sizeWdsToggleSize'default'Height: sm, default or lg. In a group the group's size wins.
labelstring | undefinedAccessible name (aria-label); required when the toggle shows only an icon.
valuestring''Value of the toggle in a wds-toggle-group.

Events

EventDescription
wds-changeCustomEvent<WdsTogglePressedChangeDetail>The user pressed or released the toggle.

Slots

SlotDescription
(default)Content: text and/or an <svg> icon.

CSS parts (::part)

PartDescription
buttonThe native <button>.

Accessibility#

Screen reader#

The group has role="group"; name it with aria-label (or aria-labelledby).

Every toggle is a button with aria-pressed, also with type="single", so screen readers announce which ones are pressed.

Name icon-only toggles with label.

Keyboard support#

KeyFunction
TabMoves focus into the group (to the last focused, pressed or first toggle) and out of it.
ArrowRightMoves focus to the next toggle (in a vertical group: ArrowDown). Wraps around.
ArrowLeftMoves focus to the previous toggle (in a vertical group: ArrowUp). Wraps around.
HomeMoves focus to the first toggle.
EndMoves focus to the last toggle.
SpacePresses or releases the focused toggle.
Footer