Gathering detailed insights and metrics for react-range
Gathering detailed insights and metrics for react-range
Gathering detailed insights and metrics for react-range
Gathering detailed insights and metrics for react-range
🎚️Range input with a slider. Accessible. Bring your own styles and markup.
npm install react-range
Typescript
Module System
Node Version
NPM Version
TypeScript (99.75%)
JavaScript (0.25%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
876 Stars
314 Commits
99 Forks
4 Watchers
10 Branches
34 Contributors
Updated on Jul 17, 2025
Latest Version
1.10.0
Package Id
react-range@1.10.0
Unpacked Size
72.54 kB
Size
18.16 kB
File Count
11
NPM Version
10.7.0
Node Version
20.14.0
Published on
Aug 07, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
22
See all the other examples and their source code! Try it out in the Stackblitz sandbox!
pnpm add react-range
1import * as React from "react"; 2import { Range } from "react-range"; 3 4const SuperSimple: React.FC = () => { 5 const [values, setValues] = React.useState([50]); 6 return ( 7 <Range 8 label="Select your value" 9 step={0.1} 10 min={0} 11 max={100} 12 values={values} 13 onChange={(values) => setValues(values)} 14 renderTrack={({ props, children }) => ( 15 <div 16 {...props} 17 style={{ 18 ...props.style, 19 height: "6px", 20 width: "100%", 21 backgroundColor: "#ccc", 22 }} 23 > 24 {children} 25 </div> 26 )} 27 renderThumb={({ props }) => ( 28 <div 29 {...props} 30 key={props.key} 31 style={{ 32 ...props.style, 33 height: "42px", 34 width: "42px", 35 backgroundColor: "#999", 36 }} 37 /> 38 )} 39 /> 40 ); 41};
aria
patterns for assistive technologies, check a11y part for accessibility infotab
and shift+tab
to focus thumbsarrow up
or arrow right
or k
to increase the thumb value by one steparrow down
or arrow left
or j
to decrease the thumb value by one steppage up
to increase the thumb value by ten stepspage down
to decrease the thumb value by ten stepsYou are responsible for the accessibility name!
Default accessibility name is Accessibility label, set with code: aria-label="Accessibility label"
, but is not visible (only for screen-readers and other assistive tech),
so make sure to use correct name by passing it to the prop called label
.
If you want to have a visible label (best practice), then use labelledBy
.
You naming options are:
label
prop (translates to aria-label
in the code)labelledBy
prop (translates to aria-labellebdy
in the code)Please check Basic
and Basic visible label
examples for more info.
Aria used on the component is following Accessible Rich Internet Applications (WAI-ARIA) 1.2 slider
role, but please be aware that different assistive technologies provide different support (especially in combination with operating systems and browsers).
Therefore please make sure to test it yourself and with people with disabilities. We can not provide prompt information about support, but are happy to add your findings to this Readme.
We need to do more testing to claim any conformance. We did make sure the component is operable with keyboard, that it is respecting ARIA patterns for slider
role and having possibility to name the component (accessible name). You are welcome to report any accessibility related findings, we look forward to add information about user tests and support for assistive technologies.
<Range />
props1renderTrack: (params: { 2 props: { 3 style: React.CSSProperties; 4 ref: React.RefObject<any>; 5 onMouseDown: (e: React.MouseEvent) => void; 6 onTouchStart: (e: React.TouchEvent) => void; 7 }; 8 children: React.ReactNode; 9 isDragged: boolean; 10 disabled: boolean; 11}) => React.ReactNode;
renderTrack
prop to define your track (root) element. Your function gets four parameters and should return a React component:
props
- this needs to be spread over the root track element, it connects mouse and touch events, adds a ref and some necessary stylingchildren
- the rendered thumbs, thumb structure should be specified in a different prop - renderThumb
isDragged
- true
if any thumb is being draggeddisabled
- true
if <Range disabled={true} />
is setThe track can be a single narrow div
as in the Super simple example; however, it might be better to use at least two nested div
s where the outer div
is much thicker and has a transparent background and the inner div
is narrow, has visible background and is centered. props
should be then spread over the outer bigger div
. Why to do this? It's nice to keep the onMouseDown
and onTouchStart
targets bigger since the thumb can be moved also by clicking on the track (in a single thumb scenario).
1renderThumb: (params: { 2 props: { 3 key: number; 4 style: React.CSSProperties; 5 tabIndex?: number; 6 "aria-valuemax": number; 7 "aria-valuemin": number; 8 "aria-valuenow": number; 9 draggable: boolean; 10 role: string; 11 onKeyDown: (e: React.KeyboardEvent) => void; 12 onKeyUp: (e: React.KeyboardEvent) => void; 13 }; 14 value: number; 15 index: number; 16 isDragged: boolean; 17}) => React.ReactNode;
renderThumb
prop to define your thumb. Your function gets four parameters and should return a React component:
props
- it has multiple props that you need to spread over your thumb elementvalue
- a number, relative value based on min
, max
, step
and the thumb's positionindex
- the thumb index (order)isDragged
- true
if the thumb is dragged, great for styling purposes1renderMark?: (params: { 2 props: { 3 key: string; 4 style: React.CSSProperties; 5 ref: React.RefObject<any>; 6 }; 7 index: number; 8}) => React.ReactNode;
renderMark
is an optional prop so you can render an element at each step. See this example. Your function gets 2 parameters and should return a React component:
props
- this needs to be spread over the root track element, it adds a ref, key and some necessary stylingindex
- index of the mark, might be useful if you want to use different styles for even/odd marksYou can use any dimensions for your marks and react-range will automatically position them at the correct place.
1values: number[];
An array of numbers. It controls the position of thumbs on the track. values.length
equals to the number of rendered thumbs.
1onChange: (values: number[]) => void;
Called when a thumb is moved, provides new values
.
1onFinalChange: (values: number[]) => void;
Called when a change is finished (mouse/touch up, or keyup), provides current values
. Use this event when you have to make for example ajax request with new values.
1min: number;
The range start. Can be decimal or negative. Default is 0
.
1max: number;
The range end. Can be decimal or negative. Default is 100
.
1step: number;
The minimal distance between two values
. Can be decimal. Default is 1
.
1allowOverlap: boolean;
When there are multiple thumbs on a single track, should they be allowed to overlap? Default is false
.
1draggableTrack: boolean;
When there are multiple thumbs on a single track, should it be possible to drag all thumbs at once? Default is false
.
1direction: Direction; 2 3enum Direction { 4 Right = "to right", 5 Left = "to left", 6 Down = "to bottom", 7 Up = "to top", 8}
It sets the orientation (vertical vs horizontal) and the direction in which the value increases. You can get this enum by:
1import { Direction } from "react-range";
Default value is Direction.Right
.
1disabled: boolean;
If true
, it ignores all touch and mouse events and makes the component not focusable. Default is false
.
1rtl: boolean;
If true
, the slider will be optimized for RTL layouts. Default is false
.
There is an additional helper function being exported from react-range
. Your track is most likely a div
with some background. What if you want to achieve a nice "progress bar" effect where the part before the thumb has different color than the part after? What if you want to have the same thing even with multiple thumbs (aka differently colored segments)? You don't need to glue together multiple divs in order to do that! You can use a single div
and set background: linear-gradient(...)
. getTrackBackground
function builds this verbose linear-gradient(...)
for you!
1getTrackBackground: (params: { 2 min: number; 3 max: number; 4 values: number[]; 5 colors: string[]; 6 direction?: Direction; 7 rtl?: boolean; 8}) => string;
min
, max
, values
and direction
should be same as for the <Range />
component. colors
is a list of colors. This needs to be true:
1values.length + 1 === colors.length;
That's because one thumb (one value) splits the track into two segments, so you need two colors.
There is a native input solution:
1<input type="range" />
However, it has some serious shortcomings:
There are also many React
based solutions but most of them are too bloated, don't support styling through CSS in JS or have lacking performance.
react-range
has two main goals:
react-range
is a more low-level approach than other libraries. It doesn't come with any styling (except some positioning) or markup. It's up to the user to specify both! Think about react-range
as a foundation for other styled input ranges.This library is tightly coupled to many DOM APIs. It would be very hard to ensure 100% test coverage just with unit tests that would not involve a lot of mocking. Or we could re-architect the library to better abstract all DOM interfaces but that would mean more code and bigger footprint.
Instead of that, react-range
adds thorough end to end tests powered by playwright.
All tests are automatically ran in Travis CI with headless chromium. This way, the public API is well tested, including pixel-perfect positioning. Also, the tests are pretty fast, reliable and very descriptive.
Do you want to run them in the dev
mode (slows down operations, opens the browser)?
1pnpm ladle serve #start the ladle server 2pnpm test:e2e:dev #run the e2e tests
CI
mode (ladle started on the background, quick, headless)
1pnpm test:e2e
This is how you can spin up the dev environment:
git clone https://github.com/tajo/react-range
cd react-range
pnpm install
pnpm ladle serve
Big big shoutout to Tom MacWright for donating the react-range
npm handle! ❤️
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 2/17 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More