@@ -171,28 +171,26 @@ export default class Scrollbar extends Component
171171 }
172172 }
173173
174- componentDidUpdate ( ) {
175- this . update ( ) ;
176-
177- const { scrollHeight = 0 , scrollWidth = 0 , clientHeight = 0 , clientWidth = 0 } = this . content ;
178- this . contentSizeTrackPreviousSize = { scrollHeight, scrollWidth, clientHeight, clientWidth} ;
179-
180- this . addListeners ( ) ;
181- }
182-
183- componentWillUpdate ( nextProps ) {
184- if ( nextProps . contentSizeTrack !== this . props . contentSizeTrack ) {
185- if ( nextProps . contentSizeTrack ) {
186- this . contentSizeTrackStart ( ) ;
174+ componentDidUpdate ( prevProps ) {
175+ if ( prevProps . contentSizeTrack !== this . props . contentSizeTrack ) {
176+ if ( prevProps . contentSizeTrack ) {
177+ this . contentSizeTrackStop ( ) ;
187178 }
188179 else {
189- this . contentSizeTrackStop ( ) ;
180+ this . contentSizeTrackStart ( ) ;
190181 }
191182 }
192- else if ( nextProps . contentSizeTrack && nextProps . contentSizeTrackInterval !== this . props . contentSizeTrackInterval ) {
183+ else if ( this . props . contentSizeTrack && this . props . contentSizeTrackInterval !== prevProps . contentSizeTrackInterval ) {
193184 this . contentSizeTrackStop ( ) ;
194185 this . contentSizeTrackStart ( ) ;
195186 }
187+
188+ this . update ( ) ;
189+
190+ const { scrollHeight = 0 , scrollWidth = 0 , clientHeight = 0 , clientWidth = 0 } = this . content ;
191+ this . contentSizeTrackPreviousSize = { scrollHeight, scrollWidth, clientHeight, clientWidth} ;
192+
193+ this . addListeners ( ) ;
196194 }
197195
198196 /**
@@ -391,7 +389,8 @@ export default class Scrollbar extends Component
391389
392390 handleDragEnd = ( ) => {
393391 this . drag = false ;
394- this . dragPrevPageX = this . dragPrevPageY = 0 ;
392+ this . dragPrevPageX = undefined ;
393+ this . dragPrevPageY = undefined ;
395394
396395 document . removeEventListener ( "mousemove" , this . handleDragEvent ) ;
397396 document . removeEventListener ( "mouseup" , this . handleDragEnd ) ;
@@ -404,14 +403,16 @@ export default class Scrollbar extends Component
404403 } ;
405404
406405 handleDragEvent = ( e ) => {
407- if ( this . dragPrevPageX ) {
408- const offset = - this . trackHorizontal . getBoundingClientRect ( ) . left + e . clientX - ( this . thumbHorizontal . clientWidth - this . dragPrevPageX ) ;
409- this . content . scrollLeft = this . computeScrollLeftForThumbOffset ( offset ) ;
410- }
411- if ( this . dragPrevPageY ) {
406+ if ( ! this . drag ) { return ; }
407+
408+ if ( this . dragPrevPageY !== undefined ) {
412409 const offset = - this . trackVertical . getBoundingClientRect ( ) . top + e . clientY - ( this . thumbVertical . clientHeight - this . dragPrevPageY ) ;
413410 this . content . scrollTop = this . computeScrollTopForThumbOffset ( offset ) ;
414411 }
412+ if ( this . dragPrevPageX !== undefined ) {
413+ const offset = - this . trackHorizontal . getBoundingClientRect ( ) . left + e . clientX - ( this . thumbHorizontal . clientWidth - this . dragPrevPageX ) ;
414+ this . content . scrollLeft = this . computeScrollLeftForThumbOffset ( offset ) ;
415+ }
415416 } ;
416417
417418 //================//
0 commit comments