@@ -142,6 +142,10 @@ function addEventListener(node, event, handler, capture) {
142142 } ,
143143 } ;
144144}
145+ // mock return value of addEventListener with noop; used as default
146+ const noopEventListener = {
147+ remove : ( ) => { } ,
148+ } ;
145149
146150function percentToValue ( percent , min , max ) {
147151 return ( ( max - min ) * percent ) / 100 + min ;
@@ -198,6 +202,12 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
198202class Slider extends React . Component {
199203 state = { currentState : 'initial' } ;
200204
205+ globalMouseMoveListener = noopEventListener ;
206+
207+ globalMouseUpListener = noopEventListener ;
208+
209+ jumpAnimationTimeoutId = - 1 ;
210+
201211 componentDidMount ( ) {
202212 if ( this . containerRef ) {
203213 this . containerRef . addEventListener ( 'touchstart' , preventPageScrolling , { passive : false } ) ;
@@ -206,6 +216,9 @@ class Slider extends React.Component {
206216
207217 componentWillUnmount ( ) {
208218 this . containerRef . removeEventListener ( 'touchstart' , preventPageScrolling , { passive : false } ) ;
219+ this . globalMouseMoveListener . remove ( ) ;
220+ this . globalMouseUpListener . remove ( ) ;
221+ clearTimeout ( this . jumpAnimationTimeoutId ) ;
209222 }
210223
211224 static getDerivedStateFromProps ( nextProps , prevState ) {
@@ -303,13 +316,8 @@ class Slider extends React.Component {
303316 handleMouseUp = event => {
304317 this . setState ( { currentState : 'normal' } ) ;
305318
306- if ( this . globalMouseUpListener ) {
307- this . globalMouseUpListener . remove ( ) ;
308- }
309-
310- if ( this . globalMouseMoveListener ) {
311- this . globalMouseMoveListener . remove ( ) ;
312- }
319+ this . globalMouseMoveListener . remove ( ) ;
320+ this . globalMouseUpListener . remove ( ) ;
313321
314322 if ( typeof this . props . onDragEnd === 'function' ) {
315323 this . props . onDragEnd ( event ) ;
@@ -373,7 +381,8 @@ class Slider extends React.Component {
373381
374382 playJumpAnimation ( ) {
375383 this . setState ( { currentState : 'jumped' } , ( ) => {
376- setTimeout ( ( ) => {
384+ clearTimeout ( this . jumpAnimationTimeoutId ) ;
385+ this . jumpAnimationTimeoutId = setTimeout ( ( ) => {
377386 this . setState ( { currentState : 'normal' } ) ;
378387 } , this . props . theme . transitions . duration . complex ) ;
379388 } ) ;
0 commit comments