Skip to content

Commit

Permalink
fix: call onBeforeChange and onAfterChange lifecycle methods when…
Browse files Browse the repository at this point in the history
… clicking track

Fixes #180
  • Loading branch information
Brian Stone committed Jun 15, 2020
1 parent 3f30cec commit e2f9473
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/ReactSlider/ReactSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,10 @@ class ReactSlider extends React.Component {
if (this.props.disabled || e.button === 2) {
return;
}
this.hasMoved = false;
if (!this.props.snapDragDisabled) {
const position = this.getMousePosition(e);
this.forceValueFromPosition(position[0], i => {
this.start(i, position[0]);
this.fireChangeEvent('onChange');
addHandlers(this.getMouseEventMap());
});
}
Expand Down Expand Up @@ -691,7 +689,12 @@ class ReactSlider extends React.Component {
}
}

this.setState({ value }, callback.bind(this, closestIndex));
this.fireChangeEvent('onBeforeChange');
this.hasMoved = true;
this.setState({ value }, () => {
callback(closestIndex);
this.fireChangeEvent('onChange');
});
}

// clear all pending timeouts to avoid error messages after unmounting
Expand All @@ -709,8 +712,6 @@ class ReactSlider extends React.Component {
thumbRef.focus();
}

this.hasMoved = false;

const { zIndices } = this.state;
// remove wherever the element is
zIndices.splice(zIndices.indexOf(i), 1);
Expand Down

0 comments on commit e2f9473

Please sign in to comment.