suiss/uim · React Native Component

Slider

A slider for picking a single value or a range by dragging one or more thumbs along a track.

Slider is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Slider on iOS in light mode

Slider renders a thin track, a filled indicator and one thumb per value. Pass a number for a single value, or an array for a range or several thumbs. The active thumb widens while it is dragged. It works horizontally or vertically.

Thumbs are aligned to the edges of the track, so they stay within it at min and max.

Installation

$ pnpm dlx @esuiss/uim@latest add slider

Manual

  1. Install the dependencies:
npx expo install cn
  1. Add the pieces it builds on: the primitives components/primitives/slider.tsx, components/primitives/use-render.tsx.

  2. Copy the source into components/ui/slider.tsx:

uniwind/components/ui/slider.tsx
import { cn } from "cn"
import * as SliderPrimitive from "@/components/primitives/slider"
import { resolveClassName } from "@/components/primitives/use-render"

function thumbIndexes(
  value: SliderPrimitive.SliderValue | undefined,
  defaultValue: SliderPrimitive.SliderValue | undefined
) {
  const source = Array.isArray(value) ? value : defaultValue
  const count = Array.isArray(source) ? source.length : 1
  return Array.from({ length: count }, (_, index) => index)
}

function Slider<
  Value extends SliderPrimitive.SliderValue = SliderPrimitive.SliderValue,
>({
  1. Update the import paths to match your project.

Usage

import { Slider } from "@/components/ui/slider"
<Slider defaultValue={50} max={100} step={1} accessibilityLabel="Volume" />

Use defaultValue for an uncontrolled slider, or value with onValueChange to control it. onValueCommitted runs when a drag or track press ends, which suits saving or fetching.

Set min, max and step to define the range; min defaults to 0 and max to 100. For ranges, minStepsBetweenValues keeps thumbs apart and thumbCollisionBehavior decides whether thumbs push each other, swap, or stop (none).

The number of thumbs comes from the array length of value or defaultValue.

Examples

Controlled

A controlled slider that shows the live and committed values.

iOS
Slider (controlled) on iOS in light mode

Range

A two-thumb price range with a step and a minimum gap.

iOS
Slider (range) on iOS in light mode

Multiple thumbs

Three thumbs that swap when they cross.

iOS
Slider (multiple thumbs) on iOS in light mode

Step

A slider that moves in decimal steps.

iOS
Slider (step) on iOS in light mode

Vertical

Single and range sliders in vertical orientation.

iOS
Slider (vertical) on iOS in light mode

Disabled

A disabled slider with muted colors.

iOS
Slider (disabled) on iOS in light mode

API Reference

Slider

ExtendsSliderPrimitive.RootProps<Value>

Accessibility

  • Each thumb has the adjustable role with its min, max and current value, so VoiceOver and TalkBack users can swipe up or down to change it.
  • accessibilityLabel on Slider is passed to every thumb; set it, since the slider has no visible label.
  • Disabled thumbs report disabled in their accessibility state.

Notes

  • The track uses bg-label-quaternary and the indicator bg-accent, with bg-control-disabled and bg-accent-disabled when disabled.
  • Thumbs use bg-surface with a shadow, or bg-label in dark mode.
  • Light and dark colors follow the system appearance.