@@ -37,6 +37,7 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
3737 * the `_host` to its original position in the DOM when it gets re-attached.
3838 */
3939 private _previousHostParent : HTMLElement ;
40+
4041 private _keydownEventsObservable : Observable < KeyboardEvent > = Observable . create ( observer => {
4142 const subscription = this . _keydownEvents . subscribe ( observer ) ;
4243 this . _keydownEventSubscriptions ++ ;
@@ -47,6 +48,9 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
4748 } ;
4849 } ) ;
4950
51+ /** Whether animations are disabled for this overlay. */
52+ private readonly _animationsDisabled : boolean ;
53+
5054 /** Stream of keydown events dispatched to this overlay. */
5155 _keydownEvents = new Subject < KeyboardEvent > ( ) ;
5256
@@ -60,11 +64,18 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
6064 private _config : ImmutableObject < OverlayConfig > ,
6165 private _ngZone : NgZone ,
6266 private _keyboardDispatcher : OverlayKeyboardDispatcher ,
63- private _document : Document ) {
67+ private _document : Document ,
68+ /**
69+ * @deprecated `animationMode` parameter to be made required.
70+ * @breaking -change 8.0.0
71+ */
72+ animationMode ?: string ) {
6473
6574 if ( _config . scrollStrategy ) {
6675 _config . scrollStrategy . attach ( this ) ;
6776 }
77+
78+ this . _animationsDisabled = animationMode === 'NoopAnimations' ;
6879 }
6980
7081 /** The overlay's HTML element */
@@ -333,6 +344,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
333344 this . _backdropElement = this . _document . createElement ( 'div' ) ;
334345 this . _backdropElement . classList . add ( 'cdk-overlay-backdrop' ) ;
335346
347+ if ( this . _animationsDisabled ) {
348+ this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-transition-disabled' ) ;
349+ }
350+
336351 if ( this . _config . backdropClass ) {
337352 this . _toggleClasses ( this . _backdropElement , this . _config . backdropClass , true ) ;
338353 }
@@ -377,24 +392,32 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
377392 detachBackdrop ( ) : void {
378393 let backdropToDetach = this . _backdropElement ;
379394
380- if ( backdropToDetach ) {
381- let timeoutId : number ;
382- let finishDetach = ( ) => {
383- // It may not be attached to anything in certain cases (e.g. unit tests).
384- if ( backdropToDetach && backdropToDetach . parentNode ) {
385- backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
386- }
395+ if ( ! backdropToDetach ) {
396+ return ;
397+ }
387398
388- // It is possible that a new portal has been attached to this overlay since we started
389- // removing the backdrop. If that is the case, only clear the backdrop reference if it
390- // is still the same instance that we started to remove .
391- if ( this . _backdropElement == backdropToDetach ) {
392- this . _backdropElement = null ;
393- }
399+ let timeoutId : number ;
400+ const finishDetach = ( ) => {
401+ // It may not be attached to anything in certain cases (e.g. unit tests) .
402+ if ( backdropToDetach && backdropToDetach . parentNode ) {
403+ backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
404+ }
394405
395- clearTimeout ( timeoutId ) ;
396- } ;
406+ // It is possible that a new portal has been attached to this overlay since we started
407+ // removing the backdrop. If that is the case, only clear the backdrop reference if it
408+ // is still the same instance that we started to remove.
409+ if ( this . _backdropElement == backdropToDetach ) {
410+ this . _backdropElement = null ;
411+ }
397412
413+ clearTimeout ( timeoutId ) ;
414+ } ;
415+
416+ if ( this . _animationsDisabled ) {
417+ // When the animations are disabled via the `NoopAnimationsModule`, we can be
418+ // fairly certain that they won't happen so we can remove the element immediately.
419+ finishDetach ( ) ;
420+ } else {
398421 backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
399422
400423 if ( this . _config . backdropClass ) {
0 commit comments