Slider
A slider with momentum and snapping, a bubble over the thumb, a rolling readout, pressable marks, limit strain, a range gap, end icons and ★ fine scrubbing.
npx @swipeui/cli add sliderWhen to use it
- Adjusting a value along a range where position matters, such as volume, brightness or distance.
- Picking a price or age range with two thumbs.
- Values with steps, such as 5-minute intervals, where you feel each step.
- Settings that preview live while dragging and save on release.
When not to use it
- Exact numbers people type. Use Number field.
- A few named options. Use Segmented control.
- Very large ranges where precision matters; pair with a text field or use Number field.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add slider- Adds
components/swipeui/ui/use-slider-gesture.ts,components/swipeui/ui/slider.tsxand 13 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Slider } from '@/components/swipeui/ui/slider';
<Slider label="Volume" defaultValue={35} startAdornment={QuietIcon} endAdornment={LoudIcon} />;Examples
A price range whose thumbs stay €20 apart, written as money:
<Slider label="Price" defaultValue={[40, 160]} max={300} step={5} minGap={20} formatValue={(v) => `€${v}`} />Labelled marks you can press, and a track that takes one step toward a press:
<Slider
label="Text size"
min={0}
max={4}
marks={[{ value: 0, label: 'XS' }, { value: 2, label: 'M' }, { value: 4, label: 'XL' }]}
trackPress="step"
/>API reference
SliderProps
| Prop | Type | Default | Description |
|---|---|---|---|
value? | | — | The value (controlled): a number, or |
defaultValue? | | | The value it starts with (uncontrolled). |
onValueChange? | | — | Reports each new step while dragging, tapping or adjusting. |
onValueCommit? | | — | Reports once when a drag, fling, tap or adjustment settles. |
min? | | | Lowest value. |
max? | | | Highest value; must exceed |
step? | | | The step values snap to. |
range? | | | A range with two thumbs. |
label? | | | The visible and spoken name. |
formatValue? | | | Writes a value for the readout, the bubble and screen readers. |
momentum? | | | A fling carries the value on and snaps to a step. |
bubble? | | | A bubble with the value over the thumb: while dragging, always, or never. |
showValue? | | | The value beside the label, rolling its digits. |
marks? | | — | Marks on the track; labelled marks can be pressed to set the value. |
limitStrain? | | | Past an end, the thumb strains toward the finger and springs back, with a limit haptic. |
minGap? | | | A range's thumbs stay at least this far apart. |
trackPress? | | | A press on the track jumps there, takes one step toward it, or does nothing. |
fineScrub? | | | ★ Drag away from the track to slow the rate to ½, ¼ and ⅛, with a tick and an announcement per band. |
grow? | | | The thumb grows while held. |
startAdornment? | | — | An icon before the track. |
endAdornment? | | — | An icon after the track. |
size? | | | Track and thumb size. |
elastic? | | | 1.x: rubber-band past the ends, as Elastic slider does. |
children? | | — | Content drawn above the track, such as a histogram. |
disabled? | | | No changes. |
haptics? | | | Haptics: a switch, or per part ( |
motion? | | | Thumb, bubble and fling motion (select, drag and number roles). |
messages? | | | Built-in strings. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | Root identifier; parts append |
Composition and behavior
- The thumb follows the finger on the UI thread, grows while held and ticks once per step. A fling carries it on and it snaps to a step;
onValueCommitfires once when it settles. - A bubble with the value rides over the thumb while dragging (or always). It sits higher over a finger than over a pointer and stays inside the track. The readout beside the label rolls its digits.
- Past an end, the thumb strains toward the finger and springs back, with one limit haptic.
- ★ Drag away from the track to scrub finely: every 48pt halves the rate (½, ¼, ⅛), with a tick and an announcement per band.
- On the web, arrows step, PageUp and PageDown jump ten steps, and Home and End go to the ends.
- 1.x:
elasticstill rubber-bands past the ends; Elastic slider adds the full elastic behaviour.
Slider settings
| Prop | Does | Default |
|---|---|---|
| min / max / step | The range and the step values snap to | 0, 100, 1 |
| range / minGap | Two thumbs; how far apart they stay | from the value, 0 |
| momentum | A fling carries on and snaps | true |
| bubble | drag, always or never | drag |
| showValue / formatValue | A rolling readout; how values are written and spoken | true, String |
| marks | Ticks, or labelled marks you can press | none |
| limitStrain | The thumb strains past an end | true |
| trackPress | jump, step or none | jump |
| fineScrub | ★ Slow the rate away from the track | true |
| grow | The thumb grows while held | true |
| startAdornment / endAdornment | Icons at the ends | none |
| size | sm, md or lg | md |
| disabled | No changes | false |
| haptics | All, or { detent, limit } | on |
| messages | Lower/upper names and scrub speeds | English |
Behavior and gestures
- Drag the thumb: it follows the finger on the UI thread, grows while held (`grow`) and ticks once per step. A fling carries it on and it snaps to a step (`momentum`); `onValueCommit` fires once when it settles.
- Press the track: the thumb jumps there (`trackPress="jump"`), takes one step toward the press (`step`), or nothing happens (`none`).
- A bubble with the value rides over the thumb while dragging (`bubble="drag"`), always, or never; it sits higher over a finger than over a pointer and stays inside the track. The readout beside the label rolls its digits (`showValue`, `formatValue`).
- Past an end the thumb strains toward the finger and springs back, with one limit haptic (`limitStrain`).
- ★ Drag away from the track: every 48pt slows the rate to ½, ¼ and ⅛, with a tick and an announcement per band (`fineScrub`).
- Labelled `marks` can be pressed to set the value. A range's thumbs keep `minGap` apart; the nearer thumb takes a drag.
- On the web, arrows step, PageUp/PageDown jump ten steps, and Home/End go to the ends.
Accessibility
- Each thumb is adjustable (a slider on the web) named by the label (with lower/upper for a range), reporting its value and the `formatValue` text, with increment and decrement actions.
- Fine-scrub speed changes are announced; every gesture has the adjustable path.
- End icons are decorative.
Motion
- Uses the
select,drag,numberandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The thumb settles on the select spring; it grows and the bubble rises on the drag spring; the readout rolls on the number role.
- Reduce Motion: no fling, strain or growth; the thumb and bubble jump; haptics stay.
Performance
- The finger is tracked on the UI thread; React hears only new steps and the release.
Notes for AI
- Pass a number for one thumb or `[low, high]` for a range. `onValueChange` reports each step, `onValueCommit` once per gesture.
- Use `formatValue` for units and money; it's also what screen readers say.
- 1.x `elastic` rubber-bands past the ends; Elastic slider adds the full elastic behaviour.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.