Skip to content

Switch

Switch represents an immediate boolean setting such as notifications, synchronization, or a persistent preference.

Import

tsx
import { Switch } from '@vellira-ui/react-native';

API

API details are generated from packages/react-native/API.md.

PropTypeRequiredDescription
accessibilityLabelstringNoAccessible name announced by assistive technology.
checkedbooleanNoControlled checked state.
defaultCheckedbooleanNoInitial checked state for uncontrolled usage.
disabledbooleanNoDisables interaction.
requiredbooleanNoMarks the control as required.
invalidbooleanNoMarks the control as invalid.
onCheckedChange(checked: boolean) => voidNoCalled when the checked state changes.

When To Use

  • Notifications.
  • Background synchronization.
  • Feature enablement.
  • Persistent user preferences.
  • Use Checkbox for form-like independent selections.

Accessibility

  • Switch uses accessibilityRole='switch' and exposes checked and disabled state through accessibilityState.
  • Provide a meaningful accessibilityLabel for every production switch whose purpose is not already obvious.
  • Required and invalid state are currently communicated through the component's accessibility hint.
  • Verify state announcements with VoiceOver and TalkBack when Switch is used in critical settings flows.

See Also

  • Checkbox - Checkbox for form-like independent selections.
  • FormField - FormField for labels, descriptions, and validation layout.

Basic Usage

tsx
<Switch accessibilityLabel='Enable notifications' defaultChecked />

Controlled Usage

tsx
import { Switch } from '@vellira-ui/react-native';
import { useState } from 'react';

export function NotificationsSetting() {
  const [enabled, setEnabled] = useState(false);

  return (
    <Switch
      accessibilityLabel='Enable notifications'
      checked={enabled}
      onCheckedChange={setEnabled}
    />
  );
}

Uncontrolled Usage

tsx
<Switch accessibilityLabel='Enable automatic updates' defaultChecked />

States

tsx
<Switch accessibilityLabel='Available setting' />

<Switch accessibilityLabel='Enabled setting' checked />

<Switch accessibilityLabel='Unavailable setting' disabled />

<Switch accessibilityLabel='Required setting' required />

<Switch accessibilityLabel='Invalid setting' invalid />

Platform Pair

Built for Vellira Design System.