@@ -171,14 +171,18 @@ export class RippleRenderer {
171171 this . _mostRecentTransientRipple = rippleRef ;
172172 }
173173
174- this . _ngZone . runOutsideAngular ( ( ) => {
175- ripple . addEventListener ( 'transitionend' , ( ) => this . _onRippleTransitionEnd ( rippleRef ) ) ;
176- } ) ;
174+ // Do not register the transition event listener if the fade-in and fade-out duration
175+ // are set to zero because the event won't be fired at all.
176+ if ( duration || animationConfig . exitDuration ) {
177+ this . _ngZone . runOutsideAngular ( ( ) => {
178+ ripple . addEventListener ( 'transitionend' , ( ) => this . _finishRippleTransition ( rippleRef ) ) ;
179+ } ) ;
180+ }
177181
178182 // In case there is no fade-in transition duration, we need to manually call the
179183 // transition end listener because `transitionend` doesn't fire if there is no transition.
180184 if ( ! duration ) {
181- this . _onRippleTransitionEnd ( rippleRef ) ;
185+ this . _finishRippleTransition ( rippleRef ) ;
182186 }
183187
184188 return rippleRef ;
@@ -214,7 +218,7 @@ export class RippleRenderer {
214218 // In case there is no fade-out transition duration, we need to manually call the
215219 // transition end listener because `transitionend` doesn't fire if there is no transition.
216220 if ( ! animationConfig . exitDuration ) {
217- this . _onRippleTransitionEnd ( rippleRef ) ;
221+ this . _finishRippleTransition ( rippleRef ) ;
218222 }
219223 }
220224
@@ -240,28 +244,39 @@ export class RippleRenderer {
240244 this . _triggerElement = element ;
241245 }
242246
243- /** Transition end event listener that fires after ripples fade in or fade out. */
244- private _onRippleTransitionEnd ( rippleRef : RippleRef ) {
245- const { config, element} = rippleRef ;
246-
247+ /** Method that will be called if the fade-in or fade-in transition completed. */
248+ private _finishRippleTransition ( rippleRef : RippleRef ) {
247249 if ( rippleRef . state === RippleState . FADING_IN ) {
248- const isMostRecentTransientRipple = rippleRef === this . _mostRecentTransientRipple ;
250+ this . _startFadeOutTransition ( rippleRef ) ;
251+ } else if ( rippleRef . state === RippleState . FADING_OUT ) {
252+ this . _destroyRipple ( rippleRef ) ;
253+ }
254+ }
249255
250- rippleRef . state = RippleState . VISIBLE ;
256+ /**
257+ * Starts the fade-out transition of the given ripple if it's not persistent and the pointer
258+ * is not held down anymore.
259+ */
260+ private _startFadeOutTransition ( rippleRef : RippleRef ) {
261+ const isMostRecentTransientRipple = rippleRef === this . _mostRecentTransientRipple ;
251262
252- // When the timer runs out while the user has kept their pointer down, we want to
253- // keep only the persistent ripples and the latest transient ripple. We do this,
254- // because we don't want stacked transient ripples to appear after their enter
255- // animation has finished.
256- if ( ! config . persistent && ( ! isMostRecentTransientRipple || ! this . _isPointerDown ) ) {
257- rippleRef . fadeOut ( ) ;
258- }
259- } else if ( rippleRef . state === RippleState . FADING_OUT ) {
260- rippleRef . state = RippleState . HIDDEN ;
261- element . parentNode ! . removeChild ( element ) ;
263+ rippleRef . state = RippleState . VISIBLE ;
264+
265+ // When the timer runs out while the user has kept their pointer down, we want to
266+ // keep only the persistent ripples and the latest transient ripple. We do this,
267+ // because we don't want stacked transient ripples to appear after their enter
268+ // animation has finished.
269+ if ( ! rippleRef . config . persistent && ( ! isMostRecentTransientRipple || ! this . _isPointerDown ) ) {
270+ rippleRef . fadeOut ( ) ;
262271 }
263272 }
264273
274+ /** Destroys the given ripple by removing it from the DOM and updating its state. */
275+ private _destroyRipple ( rippleRef : RippleRef ) {
276+ rippleRef . state = RippleState . HIDDEN ;
277+ rippleRef . element . parentNode ! . removeChild ( rippleRef . element ) ;
278+ }
279+
265280 /** Function being called whenever the trigger is being pressed using mouse. */
266281 private onMousedown = ( event : MouseEvent ) => {
267282 const isSyntheticEvent = this . _lastTouchStartEvent &&
0 commit comments