@@ -171,14 +171,18 @@ export class RippleRenderer {
171
171
this . _mostRecentTransientRipple = rippleRef ;
172
172
}
173
173
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
+ }
177
181
178
182
// In case there is no fade-in transition duration, we need to manually call the
179
183
// transition end listener because `transitionend` doesn't fire if there is no transition.
180
184
if ( ! duration ) {
181
- this . _onRippleTransitionEnd ( rippleRef ) ;
185
+ this . _finishRippleTransition ( rippleRef ) ;
182
186
}
183
187
184
188
return rippleRef ;
@@ -214,7 +218,7 @@ export class RippleRenderer {
214
218
// In case there is no fade-out transition duration, we need to manually call the
215
219
// transition end listener because `transitionend` doesn't fire if there is no transition.
216
220
if ( ! animationConfig . exitDuration ) {
217
- this . _onRippleTransitionEnd ( rippleRef ) ;
221
+ this . _finishRippleTransition ( rippleRef ) ;
218
222
}
219
223
}
220
224
@@ -240,28 +244,39 @@ export class RippleRenderer {
240
244
this . _triggerElement = element ;
241
245
}
242
246
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 ) {
247
249
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
+ }
249
255
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 ;
251
262
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 ( ) ;
262
271
}
263
272
}
264
273
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
+
265
280
/** Function being called whenever the trigger is being pressed using mouse. */
266
281
private onMousedown = ( event : MouseEvent ) => {
267
282
const isSyntheticEvent = this . _lastTouchStartEvent &&
0 commit comments