mirror of
https://github.com/wassname/slider.git
synced 2026-09-11 12:42:49 +08:00
fix: support decimal step
This commit is contained in:
+1
-1
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user