@@ -32,6 +32,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
3232 private _attachments = new Subject < void > ( ) ;
3333 private _detachments = new Subject < void > ( ) ;
3434
35+ /** Whether animations are disabled for this overlay. */
36+ private readonly _animationsDisabled : boolean ;
37+
3538 /** Stream of keydown events dispatched to this overlay. */
3639 _keydownEvents = new Subject < KeyboardEvent > ( ) ;
3740
@@ -42,11 +45,18 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
4245 private _config : ImmutableObject < OverlayConfig > ,
4346 private _ngZone : NgZone ,
4447 private _keyboardDispatcher : OverlayKeyboardDispatcher ,
45- private _document : Document ) {
48+ private _document : Document ,
49+ /**
50+ * @deprecated `animationMode` parameter to be made required.
51+ * @deletion -target 8.0.0
52+ */
53+ animationMode ?: string ) {
4654
4755 if ( _config . scrollStrategy ) {
4856 _config . scrollStrategy . attach ( this ) ;
4957 }
58+
59+ this . _animationsDisabled = animationMode === 'NoopAnimations' ;
5060 }
5161
5262 /** The overlay's HTML element */
@@ -287,6 +297,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
287297 this . _backdropElement = this . _document . createElement ( 'div' ) ;
288298 this . _backdropElement . classList . add ( 'cdk-overlay-backdrop' ) ;
289299
300+ if ( this . _animationsDisabled ) {
301+ this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-transition-disabled' ) ;
302+ }
303+
290304 if ( this . _config . backdropClass ) {
291305 this . _toggleClasses ( this . _backdropElement , this . _config . backdropClass , true ) ;
292306 }
@@ -331,24 +345,32 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
331345 detachBackdrop ( ) : void {
332346 let backdropToDetach = this . _backdropElement ;
333347
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- }
348+ if ( ! backdropToDetach ) {
349+ return ;
350+ }
341351
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- }
352+ let timeoutId : number ;
353+ const finishDetach = ( ) => {
354+ // It may not be attached to anything in certain cases (e.g. unit tests) .
355+ if ( backdropToDetach && backdropToDetach . parentNode ) {
356+ backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
357+ }
348358
349- clearTimeout ( timeoutId ) ;
350- } ;
359+ // It is possible that a new portal has been attached to this overlay since we started
360+ // removing the backdrop. If that is the case, only clear the backdrop reference if it
361+ // is still the same instance that we started to remove.
362+ if ( this . _backdropElement == backdropToDetach ) {
363+ this . _backdropElement = null ;
364+ }
365+
366+ clearTimeout ( timeoutId ) ;
367+ } ;
351368
369+ if ( this . _animationsDisabled ) {
370+ // When the animations are disabled via the `NoopAnimationsModule`, we can be
371+ // fairly certain that they won't happen so we can remove the element immediately.
372+ finishDetach ( ) ;
373+ } else {
352374 backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
353375
354376 if ( this . _config . backdropClass ) {
0 commit comments