From abdb297c16e0e2374caa2064da9c4f89e1db7637 Mon Sep 17 00:00:00 2001 From: Dylan Kirkby Date: Sun, 11 Sep 2016 19:53:15 -0700 Subject: [PATCH] chore: Add warning when range isn't a multiple of the step (#142) --- src/Slider.jsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Slider.jsx b/src/Slider.jsx index beed01d..5f08f73 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -5,6 +5,7 @@ import Track from './Track'; import DefaultHandle from './Handle'; import Steps from './Steps'; import Marks from './Marks'; +import warning from 'warning'; function noop() { } @@ -30,7 +31,7 @@ class Slider extends React.Component { constructor(props) { super(props); - const { range, min, max } = props; + const { range, min, max, step } = props; const initialValue = range ? Array.apply(null, Array(range + 1)).map(() => min) : min; const defaultValue = ('defaultValue' in props ? props.defaultValue : initialValue); const value = (props.value !== undefined ? props.value : defaultValue); @@ -44,6 +45,15 @@ class Slider extends React.Component { recent = bounds.length - 1; } + if (process.env.NODE_ENV !== 'production' && (max - min) % step !== 0) { + warning( + false, + 'Slider[max] - Slider[min] (%s) should be a multiple of Slider[step] (%s)', + max - min, + step + ); + } + this.state = { handle: null, recent,