Skip to content

ToggleGroup

alpha

A group of buttons that are pressed and released (aria-pressed): one at a time, or several with data-ts-multiple. Unlike SegmentedControl, the group can be left with no option pressed.

Forms · TaishoDS Core, in plain HTML.

Examples

One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.

Filter by status

html

One at a time, can be released

html

Icons only

html

In a form, with a disabled option

html

Class reference

Every value of each modifier, with its HTML ready to copy.

Size

Button size: xs, sm, md, or lg, the same scale as Button.

html

Orientation

horizontal (a row that wraps when it doesn’t fit) or orientation-vertical (a column; the ↑ ↓ arrows move focus).

html

States

is-selected marks the pressed option (with aria-pressed="true"); disabled on a button takes it out of navigation; is-disabled on the root disables the whole group (the JS sets disabled on every option and aria-disabled on the root).

html

Combinations

is-full-width splits the available width evenly among the options.

html

When to use

  • Filters that combine in plain sight: show only the “Ready” and “Failed” deployments.
  • Formatting or view options that turn on and off (bold, italic, code).
  • A single-option filter that can also be turned off (“all”).

When not to use

  • One option must always be chosen → segmented-control.
  • The options need a description, or there are many to pick several from → checkbox.
  • The list is long, or it doesn’t fit on one or two lines → select.
  • Each button runs an action and doesn’t stay on → button.

Do

  • The group carries an aria-label with the question (“Deployment status”); each icon-only option, its own aria-label.
  • Short labels. If they don’t fit, the group wraps, and it reads better on a single line.

Don’t

  • Don’t change an option’s text depending on whether it’s pressed. aria-pressed conveys the state.
  • Don’t mix actions (“Export”) with options that stay pressed.

TaishoDS Core

Needs Core’s JS, which hooks in through data-ts-* attributes.

Core toggles aria-pressed, releases the other options in single mode, and moves focus with the arrow keys.

Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.

  • data-ts-multiple
  • data-ts-name
  • data-ts-toggle-group
  • data-ts-toggle-group-item
  • data-ts-toggle-group-value
  • data-ts-value

What it does: Toggles aria-pressed and is-selected (without data-ts-multiple, pressing one releases the rest and pressing it again leaves the group empty) and fires a cancelable ts:change with { component: 'toggle-group', value, selection } before the change. Keyboard and Tab stop: see Accessibility. It follows aria-pressed and disabled set from code without firing; is-disabled copies disabled to every option and aria-disabled to the root; it marks each line’s ends (is-row-start, is-row-end); with data-ts-name, one <input type="hidden"> per value, and form.reset() goes back to the start.

Attribute What it does
data-ts-multipleOn the root. Lets several options be pressed at once.
data-ts-nameOn the root. The form field name. Core keeps one <input type="hidden" data-ts-toggle-group-value> per pressed value.
aria-labelOn the root, required (or aria-labelledby). The question the group answers (“Deployment status”). Without it, taisho check warns (group-without-label).
is-icon-only + aria-labelOn an icon-only option. The aria-label is its name and doesn’t change with the state (aria-pressed conveys the state). Without it, taisho check warns (icon-only-without-label).

From the CDN, without a build, load taisho.toggle-group.css along with taisho.base.css. Also load:

  • taisho.button.css
  • taisho.icon.css
  • taisho.spinner.css

For how Core works in general, see Behavior.

Theme tokens

Values you change from the theme, in themes.<theme>.components[…]. When a value has two, the second is for compact density.

Variable Type Factory value
--ts-toggle-group-pressed-fillcolorvar(--color-primary-solid)
--ts-toggle-group-pressed-textcolorvar(--color-primary-solid-contrast)
--ts-toggle-group-pressed-fill-hovercolorcolor-mix(in oklab, var(--ts-toggle-group-pressed-fill, var(--color-primary-solid)) 88%, var(--ts-toggle-group-pressed-text, var(--color-primary-solid-contrast)))

Accessibility

Implements the Button (toggle button) pattern from the WAI-ARIA APG.

  • group role with buttons that carry aria-pressed, in both modes. To disable the whole group, write is-disabled on the root and the Core JS turns it into disabled on every option and aria-disabled on the group. A radiogroup doesn’t fit: in single mode the pressed option can be released and the group left empty.
  • The group carries aria-label or aria-labelledby, which names the question (“Deployment status”); without it, taisho check warns (group-without-label). Each option takes its name from its text; an icon-only one (is-icon-only) carries aria-label and the same text in title. Without it, taisho check warns (icon-only-without-label). The name doesn’t change with the state: aria-pressed conveys that.
  • A single Tab stop: the first pressed option, or the first enabled one. Inside, the stop follows focus, so Tab leaves the group from any option. Disabled options are skipped.
  • The state doesn’t rely on color alone: the pressed option’s fill changes both background and text, and in forced colors it gets the system border (Highlight), also between two pressed options in a row.
  • When it doesn’t fit, it wraps to another line instead of overflowing (no horizontal scrolling at 320 px), with rounded ends on each line. At size xs with compact density, each option responds in at least 24 × 24 px, without overlapping the next line.

Keyboard

On top of what the browser already does (Tab moves focus, Enter activates a button).

Key What it does
→←Next and previous option, wrapping around. They only move focus; they don’t press or release anything. On an RTL page they swap: ← moves forward and → moves back.
↓↑With orientation-vertical, next and previous option (instead of → ←). They only move focus.
Home/EndFirst and last enabled option. They only move focus.
Enter/SpacePresses or releases the focused option. In single mode, pressing one releases the others, and pressing it again leaves the group empty.
TabEnters the group at a single stop: the first pressed option or, if none, the first enabled one. From any option, Tab leaves the group.

Verification

What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.

  • axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
  • keyboard Key map documented above, checked against the component.
  • screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.