Skip to content

Switch - Usage ​

The Switch component allows users to toggle between two states.

AndroidreleasedElementsreleasediOSreleasedReactreleasedVuereleased

React ​

Import ​

You can import the component like so:

js
import { Switch } from '@warp-ds/react';

or import it individually to optimize your JS bundle size by adding only the components you need:

js
import { Switch } from '@warp-ds/react/components/switch';

Syntax ​

js
  <Switch
    value={value}
    onClick={() => setValue(!value)}
    aria-label="Toggle switch"
  />

Accessibility ​

The Switch needs either aria-label or aria-labelledby to be accessible to screen readers.

Disabled property ​

There is no visual styling to a disabled button. It is recommended to display a message to the user, for example a modal or toast, stating why the user cannot toggle the switch.

Props ​

Required props ​

NameTypeDefaultDescription
valuebooleanThe value of the switch.

Optional Props ​

NameTypeDefaultDescription
idstringfalseThe unique identifier.
aria-labelstringfalseDefines a string value that labels the current element. Must be set if aria-labelledby is not defined.
aria-labelledbystringIdentifies the element (or elements) that labels the current element. Must be set if aria-label is not defined.
disabledbooleanfalseWhether the switch is disabled.

Events ​

NameDescription
onClick() => void

Questions? ​

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system