mirror of
https://github.com/wassname/slider.git
synced 2026-09-09 11:35:22 +08:00
chore: Add warning when range isn't a multiple of the step (#142)
This commit is contained in:
+11
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user