Toggle group
A set of toggles where one or many stay pressed.
In Dense data
See it live
npm run storybookWhen to use it
In Dense data: Switches a table between views and densities.
- Use it when: Switching a view or a mode between a few options, such as list and grid.
- Not when: A form answer (radio group), or actions (button group).
Instead:
- Radio group: An answer in a form.
- Button group: Actions, not a pressed choice.
Words
- Lead with the object, then the state: "Alert 2041 contained."
- Use numbers, not words for numbers.
- One verb per button. No "please", no exclamation marks.
- Use: Investigate, Filter, Assign, Escalated, Resolved. Avoid: Oops, Awesome, Please, Simply.
The labels components use, from the voice tokens:
content.action.commit: Savecontent.action.cancel: Cancelcontent.action.destroy: Deletecontent.action.retry: Retrycontent.action.empty-action: Change filters
See Voice and tone for the whole voice.
Accessibility and keyboard
| Keyboard | What happens | Not |
|---|---|---|
| undefined | Arrow keys move between toggles. | undefined |
Test before you ship:
- It is a group with a name; each toggle says whether it is pressed. undefined
Use it in code
npx open-ds add toggle-group
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Toggle group reads 3 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Toggle group's tokens to change Toggle group alone.
Dense data decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Toggle group | ||
| Corner | component.toggle-group.radiusradius.controlvar(--toggle-group-radius) | radius.2:0.125rem |
| Shadow | component.toggle-group.shadowelevation.cardvar(--toggle-group-shadow) | shadow.none |
| Item | ||
| Padding, left and right | component.toggle-group.item.padding-xspace.inset.control-xvar(--toggle-group-item-padding-x) | space.12:0.75rem |
| From the system | ||
| Corner | radius.control straight from the system, through --radius-md | radius.2 · 0.125rem (2px) |