Skip to main content
  1. Docs
  2. Components
  3. Actions

Toggle

A tool that's pressed or not. With only an icon, its name shows as its tooltip.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<button aria-pressed>Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

When to use

Use it for
  • A tool that stays on until it's pressed again: bold, mute, a filter.
  • Marking something: favourite, pin, follow.
  • Showing or hiding part of a view.
Not for

02

Anatomy

  1. 1toggle<button>The root: aria-pressed says whether it's on.
  2. 2toggle-icon-filled<svg>Leads the label. Filled while pressed, with filledWhenPressed.

03

Do and don't

Pressed is a state, not an action
DoIt stays on: the text stays bold.
Don'tA toggle that saves, then springs back.
A saved setting is a switch
DoA setting that's kept: a Switch with its label.
Don'tA toggle for a preference that's stored.
The label stays the same
DoIts name doesn't change; aria-pressed says it's on.
Don'tA label that flips: is it the state, or the action?
Not for doing
DoAn action is a Button.
Don'tA toggle that runs something.

04

Sizes

Each height follows the region's density.

SizeHeight: compact / default / comfortableIcon
sm24 / 28 / 3216px
md28 / 32 / 3616px
lg32 / 40 / 4420px

05

Content

  • Name the thing it turns on: "Bold", "Favourite".
  • Keep the label the same whether it's on or off.
  • An icon alone: its aria-label names it and shows as its tooltip.
Next — ToggleAPI