SwipeUI

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 slider
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.tsx and 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 install so versions match your SDK.

Usage

app/player.tsx
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

PropTypeDefaultDescription
value?SliderValue—

The value (controlled): a number, or [low, high] for a range.

defaultValue?SliderValue0

The value it starts with (uncontrolled).

onValueChange?((value: SliderValue) => void)—

Reports each new step while dragging, tapping or adjusting.

onValueCommit?((value: SliderValue) => void)—

Reports once when a drag, fling, tap or adjustment settles.

min?number0

Lowest value.

max?number100

Highest value; must exceed min.

step?number1

The step values snap to.

range?booleanthe shape of `value`/`defaultValue`

A range with two thumbs.

label?string'Value'

The visible and spoken name.

formatValue?((value: number) => string)String

Writes a value for the readout, the bubble and screen readers.

momentum?booleantrue

A fling carries the value on and snaps to a step.

bubble?"always" | "drag" | "never"'drag'

A bubble with the value over the thumb: while dragging, always, or never.

showValue?booleantrue

The value beside the label, rolling its digits.

marks?readonly SliderMark[]—

Marks on the track; labelled marks can be pressed to set the value.

limitStrain?booleantrue

Past an end, the thumb strains toward the finger and springs back, with a limit haptic.

minGap?number0

A range's thumbs stay at least this far apart.

trackPress?"jump" | "none" | "step"'jump'

A press on the track jumps there, takes one step toward it, or does nothing.

fineScrub?booleantrue

★ Drag away from the track to slow the rate to ½, ¼ and ⅛, with a tick and an announcement per band.

grow?booleantrue

The thumb grows while held.

startAdornment?SliderAdornment—

An icon before the track.

endAdornment?SliderAdornment—

An icon after the track.

size?"lg" | "md" | "sm"'md'

Track and thumb size.

elastic?booleanfalse

1.x: rubber-band past the ends, as Elastic slider does.

children?ReactNode—

Content drawn above the track, such as a histogram.

disabled?booleanfalse

No changes.

haptics?boolean | SelectionHapticstrue

Haptics: a switch, or per part (detent per step and scrub band, limit at the ends).

motion?MotionOverridethe app's feel

Thumb, bubble and fling motion (select, drag and number roles).

messages?Partial<SliderMessages>English

Built-in strings.

className?string—

Root classes.

style?StyleProp<ViewStyle>—

Root style.

testID?string—

Root identifier; parts append -track, -lower, -upper, -bubble-<n>, -pan, -mark-<value>.

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; onValueCommit fires 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: elastic still rubber-bands past the ends; Elastic slider adds the full elastic behaviour.

Slider settings

PropDoesDefault
min / max / stepThe range and the step values snap to0, 100, 1
range / minGapTwo thumbs; how far apart they stayfrom the value, 0
momentumA fling carries on and snapstrue
bubbledrag, always or neverdrag
showValue / formatValueA rolling readout; how values are written and spokentrue, String
marksTicks, or labelled marks you can pressnone
limitStrainThe thumb strains past an endtrue
trackPressjump, step or nonejump
fineScrub★ Slow the rate away from the tracktrue
growThe thumb grows while heldtrue
startAdornment / endAdornmentIcons at the endsnone
sizesm, md or lgmd
disabledNo changesfalse
hapticsAll, or { detent, limit }on
messagesLower/upper names and scrub speedsEnglish

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, number and press motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items