React Compound Slider
Note: react-compound-slider is not concerned with the markup or style of rendered content. The user defines the rail, handle, track and tick components. The demos on this site are provided to help people get started and are used to test changes to the library. While they generally work on mobile, the demos are not really optimized for mobile devices.

Slider

component props

NameTypeDefaultDescription
componentstring'div'String component used for slider root. Defaults to 'div'.
rootStyleobject{}An object with any inline styles you want applied to the root element.
rootPropsobject{}An object with any props you want applied to the root element.
classNamestringCSS class name applied to the root element of the slider.
domainarray[0, 100]Two element array of numbers providing the min and max values for the slider [min, max] e.g. [0, 100]. It does not matter if the slider is reversed on the screen, domain is always [min, max] with min < max.
values*arrayAn array of numbers. You can supply one for a value slider, two for a range slider or more to create n-handled sliders. The values should correspond to valid step values in the domain. The numbers will be forced into the domain if they are two small or large.
stepnumber0.1The step value for the slider.
modenumber or func1The interaction mode. Value of 1 will allow handles to cross each other. Value of 2 will keep the sliders from crossing and separated by a step. Value of 3 will make the handles pushable and keep them a step apart. ADVANCED: You can also supply a function that will be passed the current values and the incoming update. Your function should return what the state should be set as.
verticalboolfalseSet to true if the slider is displayed vertically to tell the slider to use the height to calculate positions.
reversedboolfalseReverse the display of slider values.
onChangefunction() => {}Function triggered when the value of the slider has changed. This will recieve changes at the end of a slide as well as changes from clicks on rails and tracks. Receives values.
onUpdatefunction() => {}Function called with the values at each update (caution: high-volume updates when dragging). Receives values.
onSlideStartfunction() => {}Function triggered with ontouchstart or onmousedown on a handle. Receives values.
onSlideEndfunction() => {}Function triggered on ontouchend or onmouseup on a handle. Receives values.
disabledboolfalseIgnore all mouse, touch and keyboard events.
flattenboolfalseRender slider children as siblings. This is primarily for SVG sliders. See the SVG example.
warnOnChangesboolfalseWhen true, the slider will warn if values are changed to fit domain and step values. Defaults to false.
childrenanyComponent children to render.

Rail

component props

NameTypeDefaultDescription
children*functionA function to render the rail. Note: getEventData can be called with an event and get the value and percent at that location (used for tooltips etc). activeHandleID will be a string or null. Function signature: ({ getEventData, activeHandleID, getRailProps }) => ReactNode

Handles

component props

NameTypeDefaultDescription
children*functionA function to render the handles. The function receives an object with an array of handles and functions to get handle props. Function signature: ({ handles, getHandleProps }) => ReactNode

Tracks

component props

NameTypeDefaultDescription
leftbooltrueBoolean value to control whether the left most track is included in the tracks array.
rightbooltrueBoolean value to control whether the right most track is included in the tracks array.
children*functionA function to render the tracks. The function receives an object with an array of tracks. Note: getEventData can be called with an event and get the value and percent at that location (used for tooltips etc). activeHandleID will be a string or null. Function signature: ({ getEventData, activeHandleID, tracks, getTrackProps }) => ReactNode

Ticks

component props

NameTypeDefaultDescription
countnumber10Approximate number of ticks you want to render. If you supply your own ticks using the values prop this prop has no effect.
valuesarrayThe values prop should be an array of unique numbers. Use this prop if you want to specify your own tick values instead of ticks generated by the slider. The numbers should be valid numbers in the domain and correspond to the step value. Invalid values will be coerced to the closet matching value in the domain.
children*functionA function to render the ticks. The function receives an object with an array of ticks. Note: getEventData can be called with an event and get the value and percent at that location (used for tooltips etc). activeHandleID will be a string or null. Function signature: ({ getEventData, activeHandleID, ticks }) => ReactNode