File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,7 @@ export class OverlayRef implements PortalOutlet {
331
331
let backdropToDetach = this . _backdropElement ;
332
332
333
333
if ( backdropToDetach ) {
334
+ let timeoutId : number ;
334
335
let finishDetach = ( ) => {
335
336
// It may not be attached to anything in certain cases (e.g. unit tests).
336
337
if ( backdropToDetach && backdropToDetach . parentNode ) {
@@ -343,6 +344,8 @@ export class OverlayRef implements PortalOutlet {
343
344
if ( this . _backdropElement == backdropToDetach ) {
344
345
this . _backdropElement = null ;
345
346
}
347
+
348
+ clearTimeout ( timeoutId ) ;
346
349
} ;
347
350
348
351
backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
@@ -360,7 +363,7 @@ export class OverlayRef implements PortalOutlet {
360
363
// Run this outside the Angular zone because there's nothing that Angular cares about.
361
364
// If it were to run inside the Angular zone, every test that used Overlay would have to be
362
365
// either async or fakeAsync.
363
- this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
366
+ timeoutId = this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
364
367
}
365
368
}
366
369
Original file line number Diff line number Diff line change 9
9
EventEmitter ,
10
10
} from '@angular/core' ;
11
11
import { Direction , Directionality } from '@angular/cdk/bidi' ;
12
+ import { dispatchFakeEvent } from '@angular/cdk/testing' ;
12
13
import {
13
14
ComponentPortal ,
14
15
PortalModule ,
@@ -292,6 +293,19 @@ describe('Overlay', () => {
292
293
expect ( overlayRef . backdropElement ) . toBeFalsy ( 'Expected backdrop element not to be referenced.' ) ;
293
294
} ) ) ;
294
295
296
+ it ( 'should clear the backdrop timeout if the transition finishes first' , fakeAsync ( ( ) => {
297
+ const overlayRef = overlay . create ( { hasBackdrop : true } ) ;
298
+
299
+ overlayRef . attach ( componentPortal ) ;
300
+ overlayRef . detach ( ) ;
301
+
302
+ const backdrop = overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ! ;
303
+ dispatchFakeEvent ( backdrop , 'transitionend' ) ;
304
+
305
+ // Note: we don't `tick` or `flush` here. The assertion is that
306
+ // `fakeAsync` will throw if we have an unflushed timer.
307
+ } ) ) ;
308
+
295
309
it ( 'should be able to use the `Overlay` provider during app initialization' , ( ) => {
296
310
/** Dummy provider that depends on `Overlay`. */
297
311
@Injectable ( )
You can’t perform that action at this time.
0 commit comments