Skip to content

Commit

Permalink
Fixed #2265 - Slider - onSlideEnd not called when clicking on Slider …
Browse files Browse the repository at this point in the history
…rail
  • Loading branch information
mertsincan committed Nov 6, 2021
1 parent 4934289 commit 5d68bfb
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/components/slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export class Slider extends Component {

if (!this.sliderHandleClick) {
this.updateDomData();
this.setValue(event);
const value = this.setValue(event);

if (this.props.onSlideEnd) {
this.props.onSlideEnd({ originalEvent: event, value });
}
}

this.sliderHandleClick = false;
Expand Down Expand Up @@ -211,41 +215,44 @@ export class Slider extends Component {
newValue = Math.floor(newValue);
}

this.updateValue(event, newValue);
return this.updateValue(event, newValue);
}

updateValue(event, value) {
let newValue = parseFloat(value.toFixed(10));
let parsedValue = parseFloat(value.toFixed(10));
let newValue = parsedValue;

if (this.props.range) {
if (this.handleIndex === 0) {
if (newValue < this.props.min)
newValue = this.props.min;
else if (newValue > this.value[1])
newValue = this.value[1];
if (parsedValue < this.props.min)
parsedValue = this.props.min;
else if (parsedValue > this.value[1])
parsedValue = this.value[1];
}
else {
if (newValue > this.props.max)
newValue = this.props.max;
else if (newValue < this.value[0])
newValue = this.value[0];
if (parsedValue > this.props.max)
parsedValue = this.props.max;
else if (parsedValue < this.value[0])
parsedValue = this.value[0];
}

let newValues = [...this.value];
newValues[this.handleIndex] = newValue;
newValue = [...this.value];
newValue[this.handleIndex] = parsedValue;

if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: newValues
value: newValue
});
}
}
else {
if (newValue < this.props.min)
newValue = this.props.min;
else if (newValue > this.props.max)
newValue = this.props.max;
if (parsedValue < this.props.min)
parsedValue = this.props.min;
else if (parsedValue > this.props.max)
parsedValue = this.props.max;

newValue = parsedValue;

if (this.props.onChange) {
this.props.onChange({
Expand All @@ -254,6 +261,8 @@ export class Slider extends Component {
});
}
}

return newValue;
}

componentWillUnmount() {
Expand Down

0 comments on commit 5d68bfb

Please sign in to comment.