Slider

Adjusts a bounded value, with one commit per drag.

  • Native host
  • In the first release
import { Slider, sliderPrimitive } from "nitro-ui-sdk/slider";
HeroUI Native
Slider
Expo UI
Slider
  • Slider example screen, light appearance
    Light
  • Slider example screen, dark appearance
    Dark
On this page

Adjusts a bounded numeric value along a native track (UISlider on iOS, Material Slider on Android), emitting onValueChange during dragging and onValueCommit once when the drag finishes. Use Slider for continuous or coarse stepped ranges (volume, brightness, zoom); use Stepper for exact discrete counts.

Anatomy

<Slider.Root label="Volume" min={0} max={100} step={5} defaultValue={40}>
  <Slider.Label />
  <Slider.Value />
  <Slider.Track>
    <Slider.Thumb />
  </Slider.Track>
</Slider.Root>
Part Description
Slider.Root Manages bounded value state, drag/commit lifecycle, controller attachment, and agent registration.
Slider.Label Visible label (hidden from duplicate screen-reader focus).
Slider.Value Formatted live value readout (hidden from duplicate screen-reader focus).
Slider.Track Native slider track host with active/inactive semantic colors and adjustable accessibility actions.
Slider.Thumb Style slot controlling the native thumb tint.

Usage

import { Slider } from "nitro-ui-sdk/slider";

<Slider.Root
  label="Volume"
  defaultValue={40}
  formatValue={(value) => `${Math.round(value)}%`}
/>;

Variants and sizes

variant selects "continuous" (keeps intermediate values even if step is passed) or "stepped" (snaps to step, defaulting to 1). When omitted, variant defaults to "stepped" if step is provided and "continuous" otherwise. size supports "sm", "md" (default), and "lg", each preserving at least a 44 pt touch target height.

<Slider.Root label="Brightness" variant="continuous" size="sm" defaultValue={65} />
<Slider.Root label="Contrast" variant="stepped" step={10} size="lg" defaultValue={50} />

States

Pass disabled to lock the native control, suppress change and commit callbacks, and dim captions with tokens.opacity.disabled.

<Slider.Root label="Locked gain" defaultValue={30} disabled />

Controlled

Provide value and onValueChange to control the slider. During a drag, each distinct snapped value is dispatched synchronously. A completed drag captures its final value at release. onValueCommit fires once when that interaction changes the value, after the owner accepts the final value in controlled mode.

import { useState } from "react";
import { Slider } from "nitro-ui-sdk/slider";

const [volume, setVolume] = useState(40);
const [committed, setCommitted] = useState(40);

<Slider.Root
  label="Volume"
  min={0}
  max={100}
  step={5}
  value={volume}
  onValueChange={setVolume}
  onValueCommit={setCommitted}
/>;

Props

Slider.Root

Prop Type Default Description
label string — Required visible and accessible name.
min number 0 Lower bound of the range.
max number min + 100 Upper bound of the range.
step number undefined (1 when variant="stepped") Step increment for snapping and adjustments.
value number undefined Controlled numeric value (clamped to [min, max]).
defaultValue number min Initial uncontrolled value.
onValueChange (value: number, details: ActionDetails) => void undefined Called on each value update during drag or adjustment.
onValueCommit (value: number, details: ActionDetails) => void undefined Called once when a drag finishes or a discrete action settles with a changed value.
formatValue (value: number) => string String Formats both Slider.Value and the native accessibility value description.
variant "continuous" | "stepped" "stepped" if step set, else "continuous" Controls snapping during dragging.
size "sm" | "md" | "lg" "md" Track touch target height (44, 48, or 56 pt).
disabled boolean false Disables user, agent, and controller changes.
styles PartStyles<SliderPart, SliderVariant, SliderSize, SliderState> undefined Per-part style overrides.
api Controller<SliderActions> undefined Imperative controller created with sliderPrimitive.createApi().
agentId string undefined Stable agent identity when rendered in recyclable rows.
layout SharedViewProps["layout"] undefined Additional layout props merged onto the root container.
children ReactNode Default header + track Custom part composition.

Slider.Track, Slider.Thumb, Slider.Label, Slider.Value

Prop Type Default Description
part SliderPart Matching part name Overrides the style slot resolved from styles.
children ReactNode / string From root props Optional <Slider.Thumb /> (on Track) or text override (on Label/Value).

Controller API

import { Slider, sliderPrimitive } from "nitro-ui-sdk/slider";

const api = sliderPrimitive.createApi();
<Slider.Root label="Volume" step={5} api={api} />;
api.current?.increment();
Action Signature Result
setValue (value: number, source?: ActionSource) => ChangeStatus Clamps, updates, and commits an explicit finite number ("refused" for NaN/Infinity).
increment (source?: ActionSource) => ChangeStatus Advances by one step (or 1% of range when continuous).
decrement (source?: ActionSource) => ChangeStatus Moves back by one step (or 1% of range when continuous).

Styles

Style resolvers receive { tokens, variant, size, state } where state is { min: number; max: number; step?: number; disabled: boolean; value: number }.

<Slider.Root
  label="Temperature"
  defaultValue={22}
  styles={{
    track: ({ tokens }) => ({ text: { color: tokens.colors.warning } }),
    thumb: ({ tokens }) => ({ text: { color: tokens.colors.warning } }),
  }}
/>

Accessibility

Slider.Track exposes the native adjustable slider with accessibilityLabel, formatted accessibilityValue, and native increment/decrement actions (accessibilityIncrement/accessibilityDecrement on iOS, Slider adjustable semantics on Android). Slider.Label and Slider.Value are hidden from duplicate assistive focus. Touch drags on stepped sliders trigger selectionChanged() haptics when the snapped step changes; VoiceOver, TalkBack, and keyboard adjustments report details.source === "user" without haptics.

Agent API

Action Arguments Notes
setValue number (finite) Sets and commits a value within [min, max].
increment none Advances by one step and settles controlled updates.
decrement none Decreases by one step and settles controlled updates.

Values and ranges are automatically redacted inside a secret AgentScope.

Platform notes

iOS Android
Implementation UISlider subclass starting the drag interaction before beginTracking can emit valueChanged. Material Slider clamping writes to [0, 1] and forwarding absolute user progress.
Verification Unit, type, iOS harness, and simulator screenshot verified. Written to compile; not built locally (no Android NDK on this machine).