A switch toggles the state of a setting (between on and off). Switches and checkboxes can often be used interchangeably, but the switch provides a more explicit, visible representation on a setting.



Reversed Layout

Without label

Checked with label





aria-labelstring''Adds accessible text to the switch, and should describe the isChecked="true" state. When label is defined, aria-label should be set to the text string that is visible when isChecked is true.
classNamestringAdditional classes added to the switch
defaultCheckedbooleanFlag to set the default checked value of the switch when it is uncontrolled by React state. To make the switch controlled instead use the isChecked prop, but do not use both.
hasCheckIconbooleanFlag to show if the switch has a check icon.
idstringid for the label.
isCheckedbooleantrueFlag to show if the switch is checked when it is controlled by React state. To make the switch uncontrolled instead use the defaultChecked prop, but do not use both.
isDisabledbooleanfalseFlag to show if the switch is disabled.
isReversedbooleanfalseFlag to reverse the layout of toggle and label (toggle on right).
labelReact.ReactNodeText value for the visible label when on
labelOffReact.ReactNodeText value for the visible label when off
onChange(event: React.FormEvent<HTMLInputElement>, checked: boolean) => void() => undefined as anyA callback for when the switch selection changes. (event, isChecked) => {}
ouiaIdnumber | stringValue to overwrite the randomly generated data-ouia-component-id.
ouiaSafebooleanSet the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false.

CSS variables

Expand or collapse columnSelectorVariableValue

View source on GitHub