@@ -50,6 +50,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
5050 } ;
5151 } ) ;
5252
53+ /** Whether animations are disabled for this overlay. */
54+ private readonly _animationsDisabled : boolean ;
55+
5356 /** Stream of keydown events dispatched to this overlay. */
5457 _keydownEvents = new Subject < KeyboardEvent > ( ) ;
5558
@@ -63,13 +66,19 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
6366 private _config : ImmutableObject < OverlayConfig > ,
6467 private _ngZone : NgZone ,
6568 private _keyboardDispatcher : OverlayKeyboardDispatcher ,
66- private _document : Document ) {
69+ private _document : Document ,
70+ /**
71+ * @deprecated `animationMode` parameter to be made required.
72+ * @breaking -change 8.0.0
73+ */
74+ animationMode ?: string ) {
6775
6876 if ( _config . scrollStrategy ) {
6977 _config . scrollStrategy . attach ( this ) ;
7078 }
7179
7280 this . _positionStrategy = _config . positionStrategy ;
81+ this . _animationsDisabled = animationMode === 'NoopAnimations' ;
7382 }
7483
7584 /** The overlay's HTML element */
@@ -340,6 +349,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
340349 this . _backdropElement = this . _document . createElement ( 'div' ) ;
341350 this . _backdropElement . classList . add ( 'cdk-overlay-backdrop' ) ;
342351
352+ if ( this . _animationsDisabled ) {
353+ this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-transition-disabled' ) ;
354+ }
355+
343356 if ( this . _config . backdropClass ) {
344357 this . _toggleClasses ( this . _backdropElement , this . _config . backdropClass , true ) ;
345358 }
@@ -384,24 +397,32 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
384397 detachBackdrop ( ) : void {
385398 let backdropToDetach = this . _backdropElement ;
386399
387- if ( backdropToDetach ) {
388- let timeoutId : number ;
389- let finishDetach = ( ) => {
390- // It may not be attached to anything in certain cases (e.g. unit tests).
391- if ( backdropToDetach && backdropToDetach . parentNode ) {
392- backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
393- }
400+ if ( ! backdropToDetach ) {
401+ return ;
402+ }
394403
395- // It is possible that a new portal has been attached to this overlay since we started
396- // removing the backdrop. If that is the case, only clear the backdrop reference if it
397- // is still the same instance that we started to remove.
398- if ( this . _backdropElement == backdropToDetach ) {
399- this . _backdropElement = null ;
400- }
404+ let timeoutId : number ;
405+ const finishDetach = ( ) => {
406+ // It may not be attached to anything in certain cases (e.g. unit tests).
407+ if ( backdropToDetach && backdropToDetach . parentNode ) {
408+ backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
409+ }
410+
411+ // It is possible that a new portal has been attached to this overlay since we started
412+ // removing the backdrop. If that is the case, only clear the backdrop reference if it
413+ // is still the same instance that we started to remove.
414+ if ( this . _backdropElement == backdropToDetach ) {
415+ this . _backdropElement = null ;
416+ }
401417
402- clearTimeout ( timeoutId ) ;
403- } ;
418+ clearTimeout ( timeoutId ) ;
419+ } ;
404420
421+ if ( this . _animationsDisabled ) {
422+ // When the animations are disabled via the `NoopAnimationsModule`, we can be
423+ // fairly certain that they won't happen so we can remove the element immediately.
424+ finishDetach ( ) ;
425+ } else {
405426 backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
406427
407428 if ( this . _config . backdropClass ) {
0 commit comments