SliderNew

A draggable input for selecting a value or range within a bounded interval.

Import

import { Slider } from 'heroui-native';

Anatomy

<Slider>
  <Slider.Output />
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>
  • Slider: Main container that manages slider value state, orientation, and provides context to all sub-components. Supports single value and range modes.
  • Slider.Output: Optional display of the current value(s). Supports render functions for custom formatting. Shows a formatted value label by default.
  • Slider.Track: Sizing container for Fill and Thumb elements. Reports its layout size for position calculations. Supports tap-to-position and render-function children for dynamic content (e.g. multiple thumbs for range sliders).
  • Slider.Fill: Responsive fill bar that stretches the full cross-axis of the Track. Only the main-axis position and size are computed.
  • Slider.Thumb: Draggable thumb element using react-native-gesture-handler. Centered on the cross-axis by the Track layout. Animates scale on press via react-native-reanimated. Each thumb gets role="slider" with full accessibilityValue.

Usage

Basic Usage

The Slider component uses compound parts to create a draggable value input.

<Slider defaultValue={30}>
  <Slider.Output />
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>

With Label and Output

Display a label alongside the current value output.

<Slider defaultValue={50}>
  <View className="flex-row items-center justify-between">
    <Label>Volume</Label>
    <Slider.Output />
  </View>
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>

Vertical Orientation

Render the slider vertically by setting orientation to "vertical".

<View className="h-48">
  <Slider defaultValue={50} orientation="vertical">
    <Slider.Track>
      <Slider.Fill />
      <Slider.Thumb />
    </Slider.Track>
  </Slider>
</View>

Range Slider

Pass an array as the value and use a render function on Slider.Track to create multiple thumbs.

<Slider
  defaultValue={[200, 800]}
  minValue={0}
  maxValue={1000}
  step={10}
  formatOptions={{ style: 'currency', currency: 'USD' }}
>
  <View className="flex-row items-center justify-between">
    <Label>Price range</Label>
    <Slider.Output />
  </View>
  <Slider.Track>
    {({ state }) => (
      <>
        <Slider.Fill />
        {state.values.map((_, i) => (
          <Slider.Thumb key={i} index={i} />
        ))}
      </>
    )}
  </Slider.Track>
</Slider>

Controlled Value

Use value and onChange for controlled mode. The onChangeEnd callback fires when a drag or tap interaction completes.

const [volume, setVolume] = useState(50);

<Slider value={volume} onChange={setVolume} onChangeEnd={(v) => save(v)}>
  <Slider.Output />
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>;

Custom Styling

Apply custom styles using className, classNames, or styles on the thumb and other sub-components.

<Slider defaultValue={65}>
  <Slider.Track className="h-3 rounded-full bg-success/10">
    <Slider.Fill className="rounded-full bg-success" />
    <Slider.Thumb
      classNames={{
        thumbContainer: 'size-6 rounded-full bg-success',
        thumbKnob: 'bg-success-foreground rounded-full',
      }}
      animation={{
        scale: { value: [1, 0.7] },
      }}
    />
  </Slider.Track>
</Slider>

Disabled

Disable the entire slider to prevent interaction.

<Slider defaultValue={40} isDisabled>
  <Slider.Track>
    <Slider.Fill />
    <Slider.Thumb />
  </Slider.Track>
</Slider>

Example

import { Label, Slider } from 'heroui-native';
import { useState } from 'react';
import { View, Text } from 'react-native';

export default function SliderExample() {
  const [price, setPrice] = useState<number[]>([200, 800]);

  return (
    <View className="px-8 gap-8">
      <Slider defaultValue={30}>
        <View className="flex-row items-center justify-between">
          <Label>Volume</Label>
          <Slider.Output />
        </View>
        <Slider.Track>
          <Slider.Fill />
          <Slider.Thumb />
        </Slider.Track>
      </Slider>

      <Slider
        value={price}
        onChange={setPrice}
        minValue={0}
        maxValue={1000}
        step={10}
        formatOptions={{ style: 'currency', currency: 'USD' }}
      >
        <View className="flex-row items-center justify-between">
          <Label>Price range</Label>
          <Slider.Output />
        </View>
        <Slider.Track>
          {({ state }) => (
            <>
              <Slider.Fill />
              {state.values.map((_, i) => (
                <Slider.Thumb key={i} index={i} />
              ))}
            </>
          )}
        </Slider.Track>
      </Slider>
    </View>
  );
}

You can find more examples in the GitHub repository.

API Reference

Slider

proptypedefaultdescription
childrenReact.ReactNode-Children elements to be rendered inside the slider
valuenumber | number[]-Current slider value (controlled mode)
defaultValuenumber | number[]0Default slider value (uncontrolled mode)
minValuenumber0Minimum value of the slider
maxValuenumber100Maximum value of the slider
stepnumber1Step increment for the slider
formatOptionsIntl.NumberFormatOptions-Number format options for value label formatting
orientation'horizontal' | 'vertical''horizontal'Orientation of the slider
isDisabledbooleanfalseWhether the slider is disabled
classNamestring-Additional CSS classes
animationAnimationRootDisableAll-Animation configuration for the slider
onChange(value: number | number[]) => void-Callback fired when the slider value changes during interaction
onChangeEnd(value: number | number[]) => void-Callback fired when an interaction completes (drag end or tap)
...ViewPropsViewProps-All standard React Native View props are supported

AnimationRootDisableAll

Animation configuration for the slider root component. Can be:

  • "disable-all": Disable all animations including children
  • undefined: Use default animations

Slider.Output

proptypedefaultdescription
childrenReact.ReactNode | ((props: SliderRenderProps) => React.ReactNode)-Custom content or render function receiving slider state. Defaults to formatted value label
classNamestring-Additional CSS classes
...ViewPropsViewProps-All standard React Native View props are supported

SliderRenderProps

proptypedescription
stateSliderStateCurrent slider state
orientationSliderOrientationOrientation of the slider
isDisabledbooleanWhether the slider is disabled

SliderState

proptypedescription
valuesnumber[]Current slider value(s) by thumb index
getThumbValueLabel(index: number) => stringReturns the formatted string label for a thumb

Slider.Track

proptypedefaultdescription
childrenReact.ReactNode | ((props: SliderRenderProps) => React.ReactNode)-Content or render function receiving slider state for dynamic thumb rendering
classNamestring-Additional CSS classes
hitSlopnumber8Extra touch area around the track
...ViewPropsViewProps-All standard React Native View props are supported

Slider.Fill

proptypedefaultdescription
classNamestring-Additional CSS classes
...ViewPropsViewProps-All standard React Native View props are supported

Slider.Thumb

proptypedefaultdescription
childrenReact.ReactNode-Custom thumb content. Defaults to an animated knob
indexnumber0Index of this thumb within the slider
isDisabledboolean-Whether this individual thumb is disabled
classNamestring-Additional CSS classes for the thumb container
classNamesElementSlots<ThumbSlots>-Additional CSS classes for thumb slots
stylesPartial<Record<ThumbSlots, ViewStyle>>-Inline styles for thumb slots
hitSlopnumber12Extra touch area around the thumb
animationSliderThumbAnimation-Animation configuration for the thumb knob
...ViewPropsViewProps-All standard React Native View props are supported

ElementSlots<ThumbSlots>

proptypedescription
thumbContainerstringCustom class name for the outer thumb container
thumbKnobstringCustom class name for the inner thumb knob

styles

proptypedescription
thumbContainerViewStyleStyles for the outer thumb container
thumbKnobViewStyleStyles for the inner thumb knob

SliderThumbAnimation

Animation configuration for the thumb knob scale effect. Can be:

  • false or "disabled": Disable thumb animation
  • undefined: Use default animations
  • object: Custom scale animation configuration
proptypedefaultdescription
scale.value[number, number][1, 0.9]Scale values [idle, dragging]
scale.springConfigWithSpringConfig{ damping: 15, stiffness: 200, mass: 0.5 }Spring animation configuration for scale effect

Hooks

useSlider

Hook to access the slider context. Must be used within a Slider component.

import { useSlider } from 'heroui-native';

const { values, orientation, isDisabled, getThumbValueLabel } = useSlider();

Returns

propertytypedescription
valuesnumber[]Current slider values (one per thumb)
minValuenumberMinimum value of the slider
maxValuenumberMaximum value of the slider
stepnumberStep increment
orientation'horizontal' | 'vertical'Current orientation
isDisabledbooleanWhether the slider is disabled
formatOptionsIntl.NumberFormatOptions | undefinedNumber format options for labels
getThumbPercent(index: number) => numberReturns the percentage position (0–1) for a given thumb index
getThumbValueLabel(index: number) => stringReturns the formatted label for a given thumb index
getThumbMinValue(index: number) => numberReturns the minimum allowed value for a thumb
getThumbMaxValue(index: number) => numberReturns the maximum allowed value for a thumb
updateValue(index: number, newValue: number) => voidUpdates a thumb value by index
isThumbDragging(index: number) => booleanReturns whether a given thumb is currently being dragged
setThumbDragging(index: number, dragging: boolean) => voidSets the dragging state of a thumb
trackSizenumberTrack layout width (horizontal) or height (vertical) in pixels
thumbSizenumberMeasured thumb size (main-axis dimension) in pixels

On this page