chore: Add warning when range isn't a multiple of the step (#142)

This commit is contained in:
Dylan Kirkby
2016-09-12 10:53:15 +08:00
committed by Benjy Cui
parent 67b76953c6
commit abdb297c16
+11 -1
View File
@@ -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,