Skip to content

Commit

Permalink
Merge pull request #99 from react-component/fix-bugs
Browse files Browse the repository at this point in the history
Fix #96 and #97
  • Loading branch information
just-boris committed Apr 27, 2016
2 parents f4a82e3 + e4396ae commit 025a9e7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
14 changes: 4 additions & 10 deletions src/Slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Steps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 025a9e7

Please sign in to comment.