diff --git a/examples/range.js b/examples/range.js index 2cd9a73..25c431f 100644 --- a/examples/range.js +++ b/examples/range.js @@ -95,7 +95,7 @@ ReactDOM.render(

Basic Range,`step=20`

- +

Basic Range,`step=20, dots`

diff --git a/src/Slider.jsx b/src/Slider.jsx index 07ea2d1..22919bc 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -46,12 +46,7 @@ class Slider extends React.Component { let recent; if (props.range && upperBound === lowerBound) { - if (lowerBound === max) { - recent = 'lowerBound'; - } - if (upperBound === min) { - recent = 'upperBound'; - } + recent = lowerBound === max ? 'lowerBound' : 'upperBound'; } else { recent = 'upperBound'; } @@ -240,9 +235,8 @@ class Slider extends React.Component { return this.props.vertical ? rect.top : rect.left; } - getPrecision() { - const props = this.props; - const stepString = props.step.toString(); + getPrecision(step) { + const stepString = step.toString(); let precision = 0; if (stepString.indexOf('.') >= 0) { precision = stepString.length - stepString.indexOf('.') - 1; @@ -282,7 +276,7 @@ class Slider extends React.Component { const diffs = points.map((point) => Math.abs(val - point)); const closestPoint = points[diffs.indexOf(Math.min.apply(Math, diffs))]; - return step !== null ? parseFloat(closestPoint.toFixed(this.getPrecision())) : closestPoint; + return step !== null ? parseFloat(closestPoint.toFixed(this.getPrecision(step))) : closestPoint; } calcOffset(value) { diff --git a/src/Steps.jsx b/src/Steps.jsx index 5b7a2b5..208f10a 100644 --- a/src/Steps.jsx +++ b/src/Steps.jsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import warning from 'warning'; function calcPoints(vertical, marks, dots, step, min, max) { - warning(dots ? step : true, '`Slider[step]` should be a positive number in order to make Slider[dots] work.'); + warning(dots ? step > 0 : true, '`Slider[step]` should be a positive number in order to make Slider[dots] work.'); const points = Object.keys(marks).map(parseFloat); if (dots) { for (let i = min; i <= max; i = i + step) {