React Slider UI Component (rc-slider)

11.1.9 · active · verified Sun Apr 19

rc-slider is a highly customizable UI component library for React applications, providing robust single-value sliders and dual-handle range input controls. The current stable version is 11.1.9, which receives active maintenance releases primarily focused on bug fixes and minor feature enhancements. While release cadence is not strictly fixed, updates appear frequently, addressing issues and improving accessibility. A key differentiator is its straightforward API for configuring marks, steps, and various callbacks, along with a `createSliderWithTooltip` utility for enhancing handle interactions. The library ships with comprehensive TypeScript definitions, facilitating type-safe development, and supports both modern ESM imports and CommonJS patterns. It's a foundational component used in many larger Ant Design ecosystem projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the basic `Slider` and `Range` components, including how to import the necessary CSS and how to use the `createSliderWithTooltip` utility to add value tooltips to handles.

import React from 'react';
import Slider, { Range } from 'rc-slider';
import 'rc-slider/assets/index.css';

const createSliderWithTooltip = Slider.createSliderWithTooltip;
const SliderWithTooltip = createSliderWithTooltip(Slider);
const RangeWithTooltip = createSliderWithTooltip(Range);

export default function MySliders() {
  return (
    <div style={{ padding: 20, width: '80%', margin: '0 auto' }}>
      <h3>Basic Slider</h3>
      <Slider defaultValue={50} min={0} max={100} onChange={val => console.log('Slider value:', val)} />

      <h3>Range Slider</h3>
      <Range defaultValue={[20, 80]} min={0} max={100} onChange={vals => console.log('Range values:', vals)} />

      <h3>Slider with Tooltip</h3>
      <SliderWithTooltip defaultValue={30} min={0} max={100} tipFormatter={val => `${val}%`} />

      <h3>Range with Tooltip</h3>
      <RangeWithTooltip defaultValue={[10, 60]} min={0} max={100} tipFormatter={val => `${val} units`} />
    </div>
  );
}

view raw JSON →