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