Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React Slider

License

NotificationsYou must be signed in to change notification settings

react-component/slider

Repository files navigation

Slider UI component for React

NPM versionnpm downloadbuild statusCodecovbundle sizedumi

Install

rc-slider

Example

npm start and then go tohttp://localhost:8000

Online examples:https://slider.react-component.now.sh/

Usage

Slider

importSliderfrom'@rc-component/slider';import'@rc-component/slider/assets/index.css';exportdefault()=>(<><Slider/></>);

Range

Please refer to#825 for information regarding usage ofRange.An example:

importSlider,{Range}from'@rc-component/slider';import'@rc-component/slider/assets/index.css';exportdefault()=>(<><Sliderrange/></>);

Compatibility

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Electron
Electron
IE11, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

API

createSliderWithTooltip(Slider | Range) => React.Component

An extension to make Slider or Range support Tooltip on handle.

constSlider=require('@rc-component/slider');constcreateSliderWithTooltip=Slider.createSliderWithTooltip;constRange=createSliderWithTooltip(Slider.Range);

Online demo

After Range or Slider was wrapped by createSliderWithTooltip, it will have the following props:

NameTypeDefaultDescription
tipFormatter(value: number): React.ReactNodevalue => valueA function to format tooltip's overlay
tipPropsObject{
placement: 'top',
prefixCls: 'rc-slider-tooltip',
overlay: tipFormatter(value)
}
A function to format tooltip's overlay

Common API

The following APIs are shared by Slider and Range.

NameTypeDefaultDescription
classNamestring''Additional CSS class for the root DOM node
minnumber0The minimum value of the slider
maxnumber100The maximum value of the slider
idstring''Unique identifier for the component, used for accessibility
marks{number: ReactNode} or{number: { style, label }}{}Marks on the slider. The key determines the position, and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which containsstyle andlabel properties.
stepnumber ornull1Value to be added or subtracted on each step the slider makes. Must be greater than zero, andmax -min should be evenly divisible by the step value.
Whenmarks is not an empty object,step can be set tonull, to makemarks as steps.
verticalbooleanfalseIf vertical istrue, the slider will be vertical.
handle(props) => React.ReactNodeA handle generator which could be used to customized handle.
includedbooleantrueIf the value istrue, it means a continuous value interval, otherwise, it is a independent value.
reversebooleanfalseIf the value istrue, it means the component is rendered reverse.
disabledbooleanfalseIftrue, handles can't be moved.
keyboardbooleantrueSupport using keyboard to move handlers.
dotsbooleanfalseWhen thestep value is greater than 1, you can set thedots totrue if you want to render the slider with dots.
onBeforeChangeFunctionNOOPonBeforeChange will be triggered whenontouchstart oronmousedown is triggered.
onChangeFunctionNOOPonChange will be triggered while the value of Slider changing.
onChangeCompleteFunctionNOOPonChangeComplete will be triggered whenontouchend oronmouseup is triggered.
minimumTrackStyleObjectplease usetrackStyle instead. (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x)
maximumTrackStyleObjectplease userailStyle instead (only used for slider, just for compatibility , will be deprecate at rc-slider@9.x)
handleStyleArray[Object] | Object[{}]The style used for handle. (both for slider(Object) and range(Array of Object), the array will be used for multi handle following element order)
trackStyleArray[Object] | Object[{}]The style used for track. (both for slider(Object) and range(Array of Object), the array will be used for multi track following element order)
railStyleObject{}The style used for the track base color.
dotStyleObject | (dotValue) => Object{}The style used for the dots.
activeDotStyleObject | (dotValue) => Object{}The style used for the active dots.

Slider

NameTypeDefaultDescription
defaultValuenumber0Set initial value of slider.
valuenumber-Set current value of slider.
startPointnumberundefinedTrack starts from this value. Ifundefined,min is used.
tabIndexnumber0Set the tabIndex of the slider handle.
ariaLabelForHandlestring-Set thearia-label attribute on the slider handle.
ariaLabelledByForHandlestring-Set thearia-labelledby attribute on the slider handle.
ariaRequiredboolean-Set thearia-required attribute on the slider handle.
ariaValueTextFormatterForHandle(value) => string-A function to set thearia-valuetext attribute on the slider handle. It receives the current value of the slider and returns a formatted string describing the value. SeeWAI-ARIA Authoring Practices 1.1 for more information.

Range

NameTypeDefaultDescription
defaultValuenumber[][0, 0]Set initial positions of handles.
valuenumber[]Set current positions of handles.
tabIndexnumber[][0, 0]Set the tabIndex of each handle.
ariaLabelGroupForHandlesArray[string]-Set thearia-label attribute on each handle.
ariaLabelledByGroupForHandlesArray[string]-Set thearia-labelledby attribute on each handle.
ariaValueTextFormatterGroupForHandlesArray[(value) => string]-A function to set thearia-valuetext attribute on each handle. It receives the current value of the slider and returns a formatted string describing the value. SeeWAI-ARIA Authoring Practices 1.1 for more information.
countnumber1Determine how many ranges to render, and multiple handles will be rendered (number + 1).
allowCrossbooleantrueallowCross could be set astrue to allow those handles to cross.
pushableboolean or numberfalsepushable could be set astrue to allow pushing of surrounding handles when moving a handle. When set to a number, the number will be the minimum ensured distance between handles. Example:
draggableTrackbooleanfalseOpen the track drag. open after click on the track will be invalid.

SliderTooltip

The Tooltip Component that keep following with content.

Development

npm installnpm start

Test Case

npm run test

Coverage

npm run coverage

License

rc-slider is released under the MIT license.


[8]ページ先頭

©2009-2025 Movatter.jp