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
| Prop | Type | Default | Description |
|---|---|---|---|
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-tap | Toggles it |
Accessibility
- A switch, read as on or off, with
descriptionas its hint. - The whole row (control, label and description) is one touch target and is read as one element.
- Without a visible
label,accessibilityLabelis 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.