@@ -52,6 +52,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
5252 } ;
5353 } ) ;
5454
55+ /** Whether animations are disabled for this overlay. */
56+ private readonly _animationsDisabled : boolean ;
57+
5558 /** Stream of keydown events dispatched to this overlay. */
5659 _keydownEvents = new Subject < KeyboardEvent > ( ) ;
5760
@@ -67,13 +70,19 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
6770 private _keyboardDispatcher : OverlayKeyboardDispatcher ,
6871 private _document : Document ,
6972 // @breaking -change 8.0.0 `_location` parameter to be made required.
70- private _location ?: Location ) {
73+ private _location ?: Location ,
74+ /**
75+ * @deprecated `animationMode` parameter to be made required.
76+ * @breaking -change 8.0.0
77+ */
78+ animationMode ?: string ) {
7179
7280 if ( _config . scrollStrategy ) {
7381 _config . scrollStrategy . attach ( this ) ;
7482 }
7583
7684 this . _positionStrategy = _config . positionStrategy ;
85+ this . _animationsDisabled = animationMode === 'NoopAnimations' ;
7786 }
7887
7988 /** The overlay's HTML element */
@@ -354,6 +363,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
354363 this . _backdropElement = this . _document . createElement ( 'div' ) ;
355364 this . _backdropElement . classList . add ( 'cdk-overlay-backdrop' ) ;
356365
366+ if ( this . _animationsDisabled ) {
367+ this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-transition-disabled' ) ;
368+ }
369+
357370 if ( this . _config . backdropClass ) {
358371 this . _toggleClasses ( this . _backdropElement , this . _config . backdropClass , true ) ;
359372 }
@@ -398,24 +411,32 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
398411 detachBackdrop ( ) : void {
399412 let backdropToDetach = this . _backdropElement ;
400413
401- if ( backdropToDetach ) {
402- let timeoutId : number ;
403- let finishDetach = ( ) => {
404- // It may not be attached to anything in certain cases (e.g. unit tests).
405- if ( backdropToDetach && backdropToDetach . parentNode ) {
406- backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
407- }
414+ if ( ! backdropToDetach ) {
415+ return ;
416+ }
408417
409- // It is possible that a new portal has been attached to this overlay since we started
410- // removing the backdrop. If that is the case, only clear the backdrop reference if it
411- // is still the same instance that we started to remove.
412- if ( this . _backdropElement == backdropToDetach ) {
413- this . _backdropElement = null ;
414- }
418+ let timeoutId : number ;
419+ const finishDetach = ( ) => {
420+ // It may not be attached to anything in certain cases (e.g. unit tests).
421+ if ( backdropToDetach && backdropToDetach . parentNode ) {
422+ backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
423+ }
424+
425+ // It is possible that a new portal has been attached to this overlay since we started
426+ // removing the backdrop. If that is the case, only clear the backdrop reference if it
427+ // is still the same instance that we started to remove.
428+ if ( this . _backdropElement == backdropToDetach ) {
429+ this . _backdropElement = null ;
430+ }
415431
416- clearTimeout ( timeoutId ) ;
417- } ;
432+ clearTimeout ( timeoutId ) ;
433+ } ;
418434
435+ if ( this . _animationsDisabled ) {
436+ // When the animations are disabled via the `NoopAnimationsModule`, we can be
437+ // fairly certain that they won't happen so we can remove the element immediately.
438+ finishDetach ( ) ;
439+ } else {
419440 backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
420441
421442 if ( this . _config . backdropClass ) {
0 commit comments