@@ -92,7 +92,9 @@ export class OverlayRef implements PortalHost {
9292
9393 // Add class to fade-in the backdrop after one frame.
9494 requestAnimationFrame ( ( ) => {
95- this . _backdropElement . classList . add ( 'md-overlay-backdrop-showing' ) ;
95+ if ( this . _backdropElement ) {
96+ this . _backdropElement . classList . add ( 'md-overlay-backdrop-showing' ) ;
97+ }
9698 } ) ;
9799 }
98100
@@ -101,9 +103,8 @@ export class OverlayRef implements PortalHost {
101103 let backdropToDetach = this . _backdropElement ;
102104
103105 if ( backdropToDetach ) {
104- backdropToDetach . classList . remove ( 'md-overlay-backdrop-showing' ) ;
105- backdropToDetach . classList . remove ( this . _state . backdropClass ) ;
106- backdropToDetach . addEventListener ( 'transitionend' , ( ) => {
106+ let styles = getComputedStyle ( backdropToDetach ) ;
107+ let onTransitionEnd = ( ) => {
107108 backdropToDetach . parentNode . removeChild ( backdropToDetach ) ;
108109
109110 // It is possible that a new portal has been attached to this overlay since we started
@@ -112,7 +113,16 @@ export class OverlayRef implements PortalHost {
112113 if ( this . _backdropElement == backdropToDetach ) {
113114 this . _backdropElement = null ;
114115 }
115- } ) ;
116+ } ;
117+
118+ backdropToDetach . classList . remove ( 'md-overlay-backdrop-showing' ) ;
119+ backdropToDetach . classList . remove ( this . _state . backdropClass ) ;
120+
121+ if ( parseFloat ( styles . transitionDuration ) ) {
122+ backdropToDetach . addEventListener ( 'transitionend' , onTransitionEnd ) ;
123+ } else {
124+ onTransitionEnd ( ) ;
125+ }
116126 }
117127 }
118128}
0 commit comments