@@ -83,6 +83,7 @@ export default class MDCSimpleMenuFoundation extends MDCFoundation {
8383 this . scaleY_ = 0 ;
8484 this . running_ = false ;
8585 this . selectedTriggerTimerId_ = 0 ;
86+ this . animationRequestId_ = 0 ;
8687 }
8788
8889 init ( ) {
@@ -107,6 +108,8 @@ export default class MDCSimpleMenuFoundation extends MDCFoundation {
107108
108109 destroy ( ) {
109110 clearTimeout ( this . selectedTriggerTimerId_ ) ;
111+ // Cancel any currently running animations.
112+ cancelAnimationFrame ( this . animationRequestId_ ) ;
110113 this . adapter_ . deregisterInteractionHandler ( 'click' , this . clickHandler_ ) ;
111114 this . adapter_ . deregisterInteractionHandler ( 'keyup' , this . keyupHandler_ ) ;
112115 this . adapter_ . deregisterInteractionHandler ( 'keydown' , this . keydownHandler_ ) ;
@@ -186,8 +189,9 @@ export default class MDCSimpleMenuFoundation extends MDCFoundation {
186189
187190 // Stop animation when we've covered the entire 0 - 1 range of time.
188191 if ( currentTime < 1 ) {
189- requestAnimationFrame ( ( ) => this . animationLoop_ ( ) ) ;
192+ this . animationRequestId_ = requestAnimationFrame ( ( ) => this . animationLoop_ ( ) ) ;
190193 } else {
194+ this . animationRequestId_ = 0 ;
191195 this . running_ = false ;
192196 this . adapter_ . removeClass ( MDCSimpleMenuFoundation . cssClasses . ANIMATING ) ;
193197 }
@@ -203,7 +207,7 @@ export default class MDCSimpleMenuFoundation extends MDCFoundation {
203207
204208 if ( ! this . running_ ) {
205209 this . running_ = true ;
206- requestAnimationFrame ( ( ) => this . animationLoop_ ( ) ) ;
210+ this . animationRequestId_ = requestAnimationFrame ( ( ) => this . animationLoop_ ( ) ) ;
207211 }
208212 }
209213
@@ -360,7 +364,7 @@ export default class MDCSimpleMenuFoundation extends MDCFoundation {
360364 open ( { focusIndex = null } = { } ) {
361365 this . adapter_ . saveFocus ( ) ;
362366 this . adapter_ . addClass ( MDCSimpleMenuFoundation . cssClasses . ANIMATING ) ;
363- requestAnimationFrame ( ( ) => {
367+ this . animationRequestId_ = requestAnimationFrame ( ( ) => {
364368 this . dimensions_ = this . adapter_ . getInnerDimensions ( ) ;
365369 this . applyTransitionDelays_ ( ) ;
366370 this . autoPosition_ ( ) ;
0 commit comments