Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Forms

Toggle group

A row of toggle buttons where one or several can be pressed.

Selector: mui-toggle-group

Import
import { ToggleGroup, ToggleGroupItem } from '@mushilu-san/ui/forms';
PreviewCode

Loading example…

Overview

Toggle group is a role="group" of items. Each item is a button with aria-pressed, so screen readers announce whether it is on.

Set type to single for one selected item, such as text alignment, or multiple when several can be on. value is a two-way model that holds the selected item values.

When to use

  • Switching between a few modes or formats, such as text alignment or a view mode.
  • Choosing a small set of filters where the choices are visible at once.

When not to use

  • Navigating between views. Use tabs. Use Tabs instead.
  • More than about five options. Use a select. Use Select instead.

Guidelines

Do

  • Give every item a visible text label or an icon with an accessible label.

Don't

  • Do not use a toggle group for an action that does not stay pressed.

Accessibility

Roles and attributes

ElementRoleNotes
hostgroupName it with aria-label when the context is not clear.
item—aria-pressed reflects the on state. aria-disabled when disabled.

Keyboard

KeysAction
TabShiftTabMoves focus into and out of the group.
EnterSpacePresses or releases the focused item.
  • Label the group so screen reader users know what the choice is for.

API

ToggleGroup

Selector: mui-toggle-group

NameTypeDefaultDescription
type'single' | 'multiple''single' `single` allows one pressed item; `multiple` allows several. Default `single`.
size'sm' | 'md' | 'lg''md' Size of every item: `sm`, `md` or `lg`. Default `md`.
variant'default' | 'outline''default' Visual style: `default` or `outline`. Default `default`.
disabledbooleanfalse Disables every item in the group. Accepts attribute presence, e.g. <… disabled>.
NameTypeDefaultDescription
valuestring'' For single mode: the selected value (string). For multiple: comma-joined string of selected values.

CSS parts

  • ::part(root)

ToggleGroupItem

Selector: mui-toggle-group-item

NameTypeDefaultDescription
valuerequiredstring— Value this item represents. It is the value written to the group's `value` model.
disabledbooleanfalse Disables this item only. Accepts attribute presence, e.g. <… disabled>.

CSS parts

  • ::part(button)
  • ::part(root)

Tokens

  • --mui-color-primary
  • --mui-color-primary-text
  • --mui-color-border
  • --mui-color-focus-ring
  • --mui-touch-target