Skip to content

Commit

Permalink
Fixed #2036 - Slider doesn't work with decimal step value
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed May 13, 2021
1 parent 3b72b48 commit 3276963
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ export class Slider extends Component {
setValue(event) {
let handleValue;
let pageX = event.touches ? event.touches[0].pageX : event.pageX;
let pageY = event.touches ? event.touches[0].pageY : event.pageY;

if (this.props.orientation === 'horizontal')
handleValue = ((pageX - this.initX) * 100) / (this.barWidth);
else
handleValue = (((this.initY + this.barHeight) - event.pageY) * 100) / (this.barHeight);
handleValue = (((this.initY + this.barHeight) - pageY) * 100) / (this.barHeight);

let newValue = (this.props.max - this.props.min) * (handleValue / 100) + this.props.min;

Expand All @@ -211,9 +212,9 @@ export class Slider extends Component {
}

updateValue(event, value) {
if (this.props.range) {
let newValue = value;
let newValue = parseFloat(value.toFixed(10));

if (this.props.range) {
if (this.handleIndex === 0) {
if (newValue < this.props.min)
newValue = this.props.min;
Expand All @@ -228,7 +229,7 @@ export class Slider extends Component {
}

let newValues = [...this.props.value];
newValues[this.handleIndex] = Math.floor(newValue);
newValues[this.handleIndex] = newValue;

if (this.props.onChange) {
this.props.onChange({
Expand All @@ -238,8 +239,6 @@ export class Slider extends Component {
}
}
else {
let newValue = value;

if (newValue < this.props.min)
newValue = this.props.min;
else if (newValue > this.props.max)
Expand Down

0 comments on commit 3276963

Please sign in to comment.