From 37b7f508daaa2bb4b3d6552d9e0c372b91e29d88 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Wed, 27 Apr 2016 14:29:45 +0800 Subject: [PATCH] fix: use the latest `step`, close: #96 --- src/Slider.jsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Slider.jsx b/src/Slider.jsx index a330d7f..3078a50 100644 --- a/src/Slider.jsx +++ b/src/Slider.jsx @@ -241,9 +241,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; @@ -283,7 +282,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) {