Toggle
Displays a boolean value.
Best Practices
- Use Toggle for a single boolean setting where ON takes effect immediately, like
Password ProtectionorAuto-Cancel Builds. Switch to Checkbox for a multi-select list, or to Switch for 2–3 mutually exclusive views. checkedis required and the component is controlled. Own the state and update it fromonChange.- Persist on change and surface the result in a
useToasts().success(…)toast (Password protection enabled); don’t leave the user wondering whether the flip stuck. Pair with a form footer only when the setting needs an explicitSavestep. - Disable Toggle only when the action is impossible (missing plan, locked policy); pair with helper text or a Tooltip that names the resolver.
- The label is
children, not alabelprop. Title Case noun phrase, 1–4 words, naming what is true when ON:Password Protection, notEnable Password Protection. - Render an optional one-sentence description as a sibling under the label that explains ON only. Don’t describe OFF; it’s the negation.
- Keep
labelCasing="title"(the default) so labels match other Title Case surfaces. UselabelCasing="normal"only when sentence-case content sits inline next to the toggle. - Provide an accessible name through
children,aria-label, oraria-labelledby. Geist warns in development if all three are missing. - Set
aria-labelonly when the visible label sits elsewhere on the row; otherwise letchildrencarry it so sighted and screen-reader copy stay aligned.
Was this helpful?