Switches toggle the state of a single setting on or off.
Switches are the preferred way to adjust settings on mobile. The option that the switch controls, as well as the state itās in, should be made clear from the corresponding inline label.
{{ādemoā: āBasicSwitches.jsā}}
You can provide a label to the Switch
thanks to the FormControlLabel
component.
{{ādemoā: āSwitchLabels.jsā}}
Use the size
prop to change the size of the switch.
{{ādemoā: āSwitchesSize.jsā}}
{{ādemoā: āColorSwitches.jsā}}
You can control the switch with the checked
and onChange
props:
{{ādemoā: āControlledSwitches.jsā}}
FormGroup
is a helpful wrapper used to group selection controls components that provides an easier API.
However, you are encouraged to use Checkboxes instead if multiple related controls are required. (See: When to use).
{{ādemoā: āSwitchesGroup.jsā}}
Here are some examples of customizing the component. You can learn more about this in the overrides documentation page.
{{ādemoā: āCustomizedSwitches.jsā}}
šØ If you are looking for inspiration, you can check MUI Treasuryās customization examples.
You can change the placement of the label:
{{ādemoā: āFormControlLabelPosition.jsā}}
checkbox
role not switch
role since this
role isnāt widely supported yet. Please test first if assistive technology of your
target audience supports this role properly. Then you can change the role with
<Switch inputProps={{ role: 'switch' }}>
<label>
element (FormControlLabel).aria-label
, aria-labelledby
, title
) via the inputProps
prop.<Switch value="checkedA" inputProps={{ 'aria-label': 'Switch A' }} />