mirror of
https://github.com/wassname/slider.git
synced 2026-09-09 11:35:22 +08:00
+1
-1
@@ -95,7 +95,7 @@ ReactDOM.render(
|
||||
</div>
|
||||
<div style={style}>
|
||||
<p>Basic Range,`step=20` </p>
|
||||
<Slider range step={20} defaultValue={[20, 40]} onBeforeChange={log} />
|
||||
<Slider range step={20} defaultValue={[20, 20]} onBeforeChange={log} />
|
||||
</div>
|
||||
<div style={style}>
|
||||
<p>Basic Range,`step=20, dots` </p>
|
||||
|
||||
+4
-10
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user