@@ -202,17 +202,17 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
202202 ) ;
203203 }
204204
205- window . addEventListener ( 'resize' , this . runloopAwareReposition ) ;
206- window . addEventListener ( 'orientationchange' , this . runloopAwareReposition ) ;
205+ window . addEventListener ( 'resize' , this . runloopAwareRepositionBound ) ;
206+ window . addEventListener ( 'orientationchange' , this . runloopAwareRepositionBound ) ;
207207
208208 if ( this . isTouchDevice ) {
209- document . addEventListener ( 'touchstart' , this . touchStartHandler , true ) ;
209+ document . addEventListener ( 'touchstart' , this . touchStartHandlerBound , true ) ;
210210 document . addEventListener ( 'touchend' , this . handleRootMouseDown , true ) ;
211211
212212 if ( rootElement ) {
213213 rootElement . addEventListener (
214214 'touchstart' ,
215- this . touchStartHandler ,
215+ this . touchStartHandlerBound ,
216216 true ,
217217 ) ;
218218 rootElement . addEventListener (
@@ -259,7 +259,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
259259 if ( this . isTouchDevice ) {
260260 document . removeEventListener (
261261 'touchstart' ,
262- this . touchStartHandler ,
262+ this . touchStartHandlerBound ,
263263 true ,
264264 ) ;
265265 document . removeEventListener (
@@ -271,7 +271,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
271271 if ( rootElement ) {
272272 rootElement . removeEventListener (
273273 'touchstart' ,
274- this . touchStartHandler ,
274+ this . touchStartHandlerBound ,
275275 true ,
276276 ) ;
277277 rootElement . removeEventListener (
@@ -369,28 +369,28 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
369369
370370 @action
371371 touchStartHandler ( ) : void {
372- document . addEventListener ( 'touchmove' , this . touchMoveHandler , true ) ;
372+ document . addEventListener ( 'touchmove' , this . touchMoveHandlerBound , true ) ;
373373
374374 if (
375375 this . _contentWormhole &&
376376 this . _contentWormhole . getRootNode ( ) instanceof ShadowRoot
377377 ) {
378378 const rootElement = this . _contentWormhole . getRootNode ( ) as HTMLElement ;
379- rootElement . addEventListener ( 'touchmove' , this . touchMoveHandler , true ) ;
379+ rootElement . addEventListener ( 'touchmove' , this . touchMoveHandlerBound , true ) ;
380380 }
381381 }
382382
383383 @action
384384 touchMoveHandler ( e : TouchEvent ) : void {
385385 this . touchMoveEvent = e ;
386- document . removeEventListener ( 'touchmove' , this . touchMoveHandler , true ) ;
386+ document . removeEventListener ( 'touchmove' , this . touchMoveHandlerBound , true ) ;
387387
388388 if (
389389 this . _contentWormhole &&
390390 this . _contentWormhole . getRootNode ( ) instanceof ShadowRoot
391391 ) {
392392 const rootElement = this . _contentWormhole . getRootNode ( ) as HTMLElement ;
393- rootElement . removeEventListener ( 'touchmove' , this . touchMoveHandler , true ) ;
393+ rootElement . removeEventListener ( 'touchmove' , this . touchMoveHandlerBound , true ) ;
394394 }
395395 }
396396
@@ -411,13 +411,17 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
411411
412412 @action
413413 removeGlobalEvents ( ) : void {
414- window . removeEventListener ( 'resize' , this . runloopAwareReposition ) ;
414+ window . removeEventListener ( 'resize' , this . runloopAwareRepositionBound ) ;
415415 window . removeEventListener (
416416 'orientationchange' ,
417- this . runloopAwareReposition ,
417+ this . runloopAwareRepositionBound ,
418418 ) ;
419419 }
420420
421+ touchMoveHandlerBound = ( e : TouchEvent ) => this . touchMoveHandler ( e ) ;
422+ runloopAwareRepositionBound = ( ) => this . runloopAwareReposition ( ) ;
423+ touchStartHandlerBound = ( ) => this . touchStartHandler ( ) ;
424+
421425 // Methods
422426 addScrollHandling ( dropdownElement : Element ) : void {
423427 if ( this . args . preventScroll === true ) {
@@ -497,7 +501,7 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
497501 } ;
498502 } else {
499503 this . addScrollEvents ( ) ;
500- this . removeScrollHandling = this . removeScrollEvents ;
504+ this . removeScrollHandling = this . removeScrollEvents . bind ( this ) ;
501505 }
502506 }
503507
@@ -508,15 +512,15 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
508512 // These two functions wire up scroll handling if `preventScroll` is false.
509513 // These trigger reposition of the dropdown.
510514 addScrollEvents ( ) : void {
511- window . addEventListener ( 'scroll' , this . runloopAwareReposition ) ;
515+ window . addEventListener ( 'scroll' , this . runloopAwareRepositionBound ) ;
512516 this . scrollableAncestors . forEach ( ( el ) => {
513- el . addEventListener ( 'scroll' , this . runloopAwareReposition ) ;
517+ el . addEventListener ( 'scroll' , this . runloopAwareRepositionBound ) ;
514518 } ) ;
515519 }
516520 removeScrollEvents ( ) : void {
517- window . removeEventListener ( 'scroll' , this . runloopAwareReposition ) ;
521+ window . removeEventListener ( 'scroll' , this . runloopAwareRepositionBound ) ;
518522 this . scrollableAncestors . forEach ( ( el ) => {
519- el . removeEventListener ( 'scroll' , this . runloopAwareReposition ) ;
523+ el . removeEventListener ( 'scroll' , this . runloopAwareRepositionBound ) ;
520524 } ) ;
521525 }
522526}
0 commit comments