@@ -331,43 +331,45 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
331
331
detachBackdrop ( ) : void {
332
332
let backdropToDetach = this . _backdropElement ;
333
333
334
- if ( backdropToDetach ) {
335
- let timeoutId : number ;
336
- let finishDetach = ( ) => {
337
- // It may not be attached to anything in certain cases (e.g. unit tests).
338
- if ( backdropToDetach && backdropToDetach . parentNode ) {
339
- backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
340
- }
341
-
342
- // It is possible that a new portal has been attached to this overlay since we started
343
- // removing the backdrop. If that is the case, only clear the backdrop reference if it
344
- // is still the same instance that we started to remove.
345
- if ( this . _backdropElement == backdropToDetach ) {
346
- this . _backdropElement = null ;
347
- }
334
+ if ( ! backdropToDetach ) {
335
+ return ;
336
+ }
348
337
349
- clearTimeout ( timeoutId ) ;
350
- } ;
338
+ let timeoutId : number ;
339
+ let finishDetach = ( ) => {
340
+ // It may not be attached to anything in certain cases (e.g. unit tests).
341
+ if ( backdropToDetach && backdropToDetach . parentNode ) {
342
+ backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
343
+ }
351
344
352
- backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
345
+ // It is possible that a new portal has been attached to this overlay since we started
346
+ // removing the backdrop. If that is the case, only clear the backdrop reference if it
347
+ // is still the same instance that we started to remove.
348
+ if ( this . _backdropElement == backdropToDetach ) {
349
+ this . _backdropElement = null ;
350
+ }
353
351
354
352
if ( this . _config . backdropClass ) {
355
- this . _toggleClasses ( backdropToDetach , this . _config . backdropClass , false ) ;
353
+ this . _toggleClasses ( backdropToDetach ! , this . _config . backdropClass , false ) ;
356
354
}
357
355
358
- this . _ngZone . runOutsideAngular ( ( ) => {
359
- backdropToDetach ! . addEventListener ( 'transitionend' , finishDetach ) ;
360
- } ) ;
356
+ clearTimeout ( timeoutId ) ;
357
+ } ;
361
358
362
- // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
363
- // In this case we make it unclickable and we try to remove it after a delay.
364
- backdropToDetach . style . pointerEvents = 'none' ;
359
+ backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
365
360
366
- // Run this outside the Angular zone because there's nothing that Angular cares about.
367
- // If it were to run inside the Angular zone, every test that used Overlay would have to be
368
- // either async or fakeAsync.
369
- timeoutId = this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
370
- }
361
+ this . _ngZone . runOutsideAngular ( ( ) => {
362
+ backdropToDetach ! . addEventListener ( 'transitionend' , finishDetach ) ;
363
+ } ) ;
364
+
365
+ // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
366
+ // In this case we make it unclickable and we try to remove it after a delay.
367
+ backdropToDetach . style . pointerEvents = 'none' ;
368
+
369
+ // Run this outside the Angular zone because there's nothing that Angular cares about.
370
+ // If it were to run inside the Angular zone, every test that used Overlay would have to be
371
+ // either async or fakeAsync.
372
+ timeoutId = this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
371
373
}
372
374
373
375
/** Toggles a single CSS class or an array of classes on an element. */
0 commit comments