Skip to content

Repository files navigation

@rc-component/slider

Ant Design Part of the Ant Design ecosystem.

🎚️ Accessible React slider for single values, ranges, marks, and editable handles.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

  • Supports single-value and range sliders with one shared component.
  • Provides marks, dots, keyboard interaction, reverse and vertical layouts.
  • Supports editable range handles and draggable tracks through range config.
  • Exposes semantic classNames and styles slots for tracks, rail, and handles.

Install

npm install @rc-component/slider

Usage

importSliderfrom'@rc-component/slider';import'@rc-component/slider/assets/index.css';exportdefault()=><SliderdefaultValue={30}/>;
importSliderfrom'@rc-component/slider';import'@rc-component/slider/assets/index.css';exportdefault()=>(<Sliderrange={{draggableTrack: true}}marks={{0: '0',50: '50',100: '100'}}defaultValue={[20,60]}/>);

Online preview: https://slider.react-component.vercel.app/

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Slider

NameTypeDefaultDescription
activeDotStyleReact.CSSProperties | (dotValue: number) => React.CSSProperties-Style for active dots.
activeHandleRenderHandlesProps['handleRender']-Render function for the active handle.
allowCrossbooleantrueAllow handles to cross in range mode.
ariaLabelForHandlestring | string[]-aria-label for handle elements.
ariaLabelledByForHandlestring | string[]-aria-labelledby for handle elements.
ariaRequiredboolean-aria-required for handle elements.
ariaValueTextFormatterForHandle((value: number) => string) | ((value: number) => string)[]-Formatter for aria-valuetext.
autoFocusboolean-Focus the slider on mount.
classNamestring-Additional class name.
classNamesPartial<Record<'tracks' | 'track' | 'rail' | 'handle', string>>-Semantic class names for internal slots.
countnumber-Deprecated. Use range.minCount or range.maxCount.
defaultValuenumber | number[]-Initial value.
disabledboolean | boolean[]falseDisable all handles or specific handles.
dotsbooleanfalseShow dots at each valid step position.
dotStyleReact.CSSProperties | (dotValue: number) => React.CSSProperties-Style for dots.
handleRenderHandlesProps['handleRender']-Custom handle renderer.
handleStyleReact.CSSProperties | React.CSSProperties[]-Deprecated. Use styles.handle.
idstring-Root id.
includedbooleantrueWhether the track is rendered as a continuous selected interval.
keyboardbooleantrueEnable keyboard interaction.
marksRecord<string | number, ReactNode | MarkObj>-Slider marks.
maxnumber100Maximum value.
minnumber0Minimum value.
onAfterChange(value) => void-Deprecated. Use onChangeComplete.
onBeforeChange(value) => void-Deprecated. Use onChange.
onBlur(event) => void-Blur handler.
onChange(value) => void-Triggered while value changes.
onChangeComplete(value) => void-Triggered when interaction completes.
onFocus(event) => void-Focus handler.
prefixClsstring'rc-slider'Prefix class name.
pushableboolean | numberfalsePush adjacent handles in range mode.
railStyleReact.CSSProperties-Deprecated. Use styles.rail.
rangeboolean | RangeConfigfalseEnable range mode or configure editable range behavior.
reversebooleanfalseRender in reverse direction.
startPointnumberminStart point for a single-value track.
stepnumber | null1Step size. Use null to use marks as steps.
styleReact.CSSProperties-Root style.
stylesPartial<Record<'tracks' | 'track' | 'rail' | 'handle', React.CSSProperties>>-Semantic styles for internal slots.
tabIndexnumber | number[]0Handle tab index.
trackboolean-Whether to render track elements.
trackStyleReact.CSSProperties | React.CSSProperties[]-Deprecated. Use styles.track.
valuenumber | number[]-Controlled value.
verticalbooleanfalseRender vertically.

RangeConfig

NameTypeDefaultDescription
draggableTrackbooleanfalseAllow dragging the selected range track.
editablebooleanfalseAllow adding or removing range handles.
maxCountnumber-Maximum handle count when editable.
minCountnumber-Minimum handle count when editable.

Ref

NameTypeDescription
blur() => voidBlur the slider.
focus() => voidFocus the slider.

Development

npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/slider is released under the MIT license.

About

🎚️ Accessible React slider for single values, ranges, marks, and editable handles.

Topics

Resources

Stars

3.1k stars

Watchers

46 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages