Switch
Switch turns a single setting on or off, and the change takes effect straight away.
<Switch id="notify" defaultChecked /><Text render={<label htmlFor="notify" />}>Notifications</Text>Use a Switch for a setting that applies as soon as it changes, with no save button. When the choice waits until a form is submitted, use a Checkbox instead.
When it is off, the track is a neutral channel. When it is on, the track fills with the accent colour. A Switch is a little larger than a Checkbox of the same size, and it has no tone or emphasis, so every switch looks the same.
The label is a separate element placed beside the Switch. Use a Text rendered as a label, with htmlFor set to the Switch's id. Inside a Field, put the Switch in a FieldItem with a FieldLabel and FieldDescription, and they are connected for you.
The area that responds to a press is larger than the track, so a Switch is easy to hit with a finger. On a touch screen the whole Switch grows, but the density setting doesn't change it.
A screen reader announces a Switch as a switch that is on or off, and Space changes it. A hidden checkbox goes with it, so a Switch with a name sends its value with a form.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
size? | "1" | "2" | "3" | "4" | The size step of the switch, from 1 to 4. |
toneandemphasis— A Switch is always neutral when off and uses the accent colour when on, so every switch in an app reads the same way.children— The label sits beside the Switch rather than inside it, so that the row decides the space between them. Put aTextrendered as alabelnext to it.readOnly— HTML has no read-only switch, so there is no familiar look to copy. Usedisabledfor a setting that can't be changed, as you would with aCheckbox.