Components/Form

Toggle

Toggles are switches for a setting that takes effect the moment it is flipped. Nothing is staged and there is nothing to submit afterwards, so a switch suits a change that is instant and easy to reverse. The words beside it name the thing being switched, and the switch itself says which way it is set.

import { Toggle } from '@growth-protocol-ai/alpha';

On this page

state
Toggle.tsxtsx
1import { Toggle } from '@growth-protocol-ai/alpha';
2
3<Toggle
4 key={String(defaultChecked)}
5 label="Weekly summary email"
6 defaultChecked={false}
7 disabled={false}
8/>

When to use

Reach for a toggle when flipping it is the action — a setting that applies on the spot and needs no Save under it, like a notification a reader turns off or a preview they turn on. Name it for the thing being switched rather than for the act: a name written as an instruction has to be read twice, and it disagrees with the control the moment the reader flips it.

When not to use

Do not use a switch for a value that travels with a form and lands on submit — that is a Checkbox, whatever the two look like side by side. The test is what happens if the reader closes the page a second after clicking: if the change is already made it is a switch, and if it is waiting for a Save it is a checkbox. Answers that rule each other out are a Radio group.