Skip to content
Stylhero 0.6.2
React Native

Theme

Core

Feedback

Inputs

Navigation

Overlays

React Native / Inputs

Switch

On/off setting that takes effect right away (use Checkbox inside forms that are submitted). Looks the same on iOS and Android, is announced as a switch with its state, and mirrors in right-to-left layouts.

import { Switch } from "@stylhero/native";

Example

import { useState } from "react";
import { Switch } from "@stylhero/native";

function SwitchExample() {
  const [alerts, setAlerts] = useState(true);
  return (
    <Switch
      label="Price alerts"
      description="Tell me when a part in a saved build gets cheaper."
      value={alerts}
      onValueChange={setAlerts}
    />
  );
}

Props

PropTypeDefaultDescription
onValueChange required (value: boolean) => void -
value required boolean -
accessibilityLabel string -
description string - Help text under the label.
disabled boolean -
label string -
ref Ref<ComponentRef<typeof View>> -
style StyleProp<ViewStyle> -
testID string -

Screen reader gestures

Gesture (VoiceOver / TalkBack)Does
Double-tapToggles it

Accessibility

  • A switch, read as on or off, with description as its hint.
  • The whole row (control, label and description) is one touch target and is read as one element.
  • Without a visible label, accessibilityLabel is required.
  • The thumb animation is skipped when Reduce Motion is on, and mirrors in right-to-left layouts.

Generated from src/components/Switch.tsx. Something wrong or missing? Open an issue.