Components
Switch

Switch

A toggle control for binary on/off states. Semantically uses role="switch" and a hidden <input type="checkbox"> for full accessibility.

Import

import { Switch } from '@mitek/ui';

Default

<Switch />
<Switch defaultChecked />

With label

<Switch label="Enable notifications" />
<Switch label="Dark mode" defaultChecked />

With description

Receive product updates and announcements.Add an extra layer of security to your account.
<Switch
  label="Marketing emails"
  description="Receive product updates and announcements."
/>

Label position

<Switch label="Label on right (default)" labelPosition="right" />
<Switch label="Label on left" labelPosition="left" />

Sizes

<Switch size="sm" label="Small" />
<Switch size="md" label="Medium" />
<Switch size="lg" label="Large" />

Disabled

<Switch label="Disabled off" disabled />
<Switch label="Disabled on" disabled defaultChecked />

Controlled

const [enabled, setEnabled] = React.useState(false);
 
<Switch
  label="Notifications"
  checked={enabled}
  onChange={(e) => setEnabled(e.target.checked)}
/>

Props

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Size of the switch
labelReactNodeLabel next to the switch
descriptionstringHelper text below the label
labelPosition'left' | 'right''right'Which side the label appears
checkedbooleanControlled checked state
defaultCheckedbooleanfalseUncontrolled initial state
disabledbooleanfalseDisables interaction
onChangeChangeEventHandlerCalled when toggled
idstringautoLinks label for to input id
classNamestringAdditional class on the wrapper