Switch

Basic

It receives the same props as controlled inputs, such as checked and onChange.

useCheckboxState

A Switch acts as a checkbox, so useCheckboxState is usable exactly like on a Checkbox.

Sizes

Set scales using scale prop like "xs", "sm", "lg" or "xl". The default scale is "base".

Disabled

Disable using disabled prop.

With labels

Add labels using labeled props. Set custom labels using labelOn and labelOff.

Accessibility

Switch uses Reakit Checkbox under the hood, it means it follows WAI-ARIA Checkbox Pattern.

Read more about accessibility on Reakit.

API

useCheckboxState

See Reakit documentation.

Switch

PropertyTypeRequiredDefaultDescription
checkedbooleanfalse-Checkbox's checked state. If present, it's used instead of state.
disabledbooleanfalse-Same as the HTML attribute.
focusablebooleanfalse-When an element is `disabled`, it may still be `focusable`. It works similarly to `readOnly` on form elements. In this case, only `aria-disabled` will be set.
onChangefunctionfalse-Same as the "checkbox" `onChange` prop.
scale
enum
falsebaseControl the size of the component.
Show xstyled properties

Switch also includes a bunch of state properties, see Reakit documentation.