Compare commits

...
1 Commits
Author SHA1 Message Date
Benjy Cui ee0dd09a4f fix: support decimal step 2015-11-23 16:00:21 +08:00
2 changed files with 12 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "rc-slider",
"version": "3.1.1",
"version": "3.1.2",
"description": "slider ui component for react",
"keywords": [
"react",
+11 -1
View File
@@ -203,6 +203,16 @@ class Slider extends React.Component {
return rect.left;
}
getPrecision() {
const props = this.props;
const stepString = props.step.toString();
let precision = 0;
if (stepString.indexOf('.') >= 0) {
precision = stepString.length - stepString.indexOf('.') - 1;
}
return precision;
}
trimAlignValue(v) {
const state = this.state || {};
const {handle, lowerBound, upperBound} = state;
@@ -231,7 +241,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 closestPoint;
return step !== null ? parseFloat(closestPoint.toFixed(this.getPrecision())) : closestPoint;
}
calcOffset(value) {