Toggle
Toggle is a button that stays pressed until you press it again, for things like bold text or a filter.
<ToggleGroup aria-label="Format" defaultValue={["bold"]}> <Toggle value="bold" aria-label="Bold">{icon}</Toggle> <Toggle value="italic" aria-label="Italic">{icon}</Toggle></ToggleGroup>Use a Toggle for something that is on or off while you work, such as bold in a formatting bar, a filter, or a panel that you show or hide. When the person must pick exactly one of several options, use a SegmentedControl. Use a Switch for a saved setting, a Checkbox for an option in a form, and a Button for an action that runs and finishes.
A Toggle looks and behaves like a Button, except that its state sets its style. It is quiet when off and gets a soft fill when pressed, so it has no emphasis prop. tone gives the toggle a meaning, such as destructive when turning it on blocks something.
Use a ToggleGroup for several toggles that share one array of pressed values, such as bold, italic and underline. Each toggle in the group still turns on and off by itself. The group has no layout of its own, so use render to make it a Flex or a Stack.
A screen reader announces a Toggle as a button that is pressed or not pressed, and Space or Enter changes it. In a ToggleGroup, the whole group is one tab stop, and the arrow keys move focus between the toggles without pressing them. Set orientation to vertical when the toggles run in a column.
- Switch when it is a setting that stays on or off.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
A button that stays pressed
Toggle
Toggle is a button that stays pressed until you press it again, for things like bold text or a filter.
| Prop | Type | What it does |
|---|---|---|
aria-label? | string | The name of the button for screen readers. |
aria-labelledby? | string | The id of an element on the page that names this button. |
backdrop? | boolean | Set backdrop when the toggle sits over other content, such as an image. |
bordered? | boolean | Adds a thin border. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
defaultPressed? | boolean | Whether the toggle starts on. |
iconOnly | true | Makes the button square and shows only the icon in children. |
leading? | React.ReactNode | The slot before the label, usually an icon. |
onPressedChange? | (pressed: boolean) => void | Fires when the pressed state changes, with the new state. |
pressed? | boolean | Whether the toggle is on. |
size? | "1" | "2" | "3" | "4" | The size step of the toggle, from 1 to 4. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
tone? | "neutral" | "accent" | "destructive" | "blue" | "green" | "orange" | "amber" | "pink" | "purple" | "success" | "warning" | "info" | The meaning of the toggle's state, which sets its colour. |
trailing? | React.ReactNode | The slot after the label. |
value? | string | The value this toggle contributes to a ToggleGroup. |
It also takes every prop of a <button>.
emphasis— A Toggle's style shows whether it is on: quiet when off and filled when pressed. Choosing an emphasis could make an unpressed toggle look pressed.loading— A Toggle changes state at once and never waits for work to finish. Use aButtonwithloadingfor a task that runs, or aSwitchfor a saved setting.- A single-select group — A group where only one option can be on is a radio group. Use a
SegmentedControlfor that, so a screen reader announces it correctly. render— A Toggle is always abutton, because its pressed state is announced through that element's attributes. Swapping the element would lose that announcement.