React Native / Inputs
Slider
Pick a number in a range by dragging. Screen reader users swipe up or down to change it (the "adjustable" role), and hear the formatted value. The whole 44pt-high row takes touches, so the thumb doesn't need to be hit exactly.
import { Slider } from "@stylhero/native";
Example
import { useState } from "react";
import { Slider } from "@stylhero/native";
function SliderExample() {
const [limit, setLimit] = useState(800);
return (
<Slider
label="Price limit"
value={limit}
onChange={setLimit}
min={100}
max={2000}
step={50}
formatValue={(v) => `$${v}`}
/>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label required |
string |
- | Visible label, also read by screen readers. |
onChange required |
(value: number) => void |
- | Called while dragging and on each screen reader swipe. |
value required |
number |
- | |
accessibilityStep |
number |
- | How much one screen reader swipe up/down changes the value. Default step,
or about a tenth of the range (snapped to step) when that would take more
than 20 swipes end to end. |
disabled |
boolean |
- | |
formatValue |
(value: number) => string |
String |
Text for the value, shown next to the label and read by screen readers, e.g. (v) => $${v}. |
hideLabel |
boolean |
- | |
hint |
string |
- | Help text under the slider. |
max |
number |
100 |
Default 100. |
min |
number |
0 |
Default 0. |
onChangeEnd |
(value: number) => void |
- | Called once when a drag ends, e.g. to save or fetch. Also after each screen reader swipe. |
showValue |
boolean |
true |
Show the formatted value next to the label. Default true. |
step |
number |
1 |
Values snap to multiples of this from min. Default 1. |
style |
StyleProp<ViewStyle> |
- | |
testID |
string |
- |
Screen reader gestures
| Gesture (VoiceOver / TalkBack) | Does |
|---|---|
| Swipe up / down | Increases / decreases the value and reads it, formatted by formatValue |
Accessibility
- An adjustable control with min, max and the current value. On long ranges each swipe moves about 10% (
accessibilityStepchanges it), so nobody has to swipe 100 times. onChangeEndruns after each swipe, the same as when a drag ends.
Generated from src/components/Slider.tsx. Something wrong or missing? Open an issue.