@@ -845,35 +845,41 @@ export class MatSelect
845845 /** Triggers the exit animation and detaches the overlay at the end. */
846846 private _exitAndDetach ( ) {
847847 if ( this . _animationsDisabled || ! this . panel ) {
848- this . _overlayDir . detachOverlay ( ) ;
848+ this . _detachOverlay ( ) ;
849849 return ;
850850 }
851851
852- this . _ngZone . runOutsideAngular ( ( ) => {
853- this . _cleanupDetach ?.( ) ;
854- this . _cleanupDetach = ( ) => {
855- cleanupEvent ( ) ;
856- clearTimeout ( exitFallbackTimer ) ;
857- this . _cleanupDetach = undefined ;
858- } ;
852+ this . _cleanupDetach ?.( ) ;
853+ this . _cleanupDetach = ( ) => {
854+ cleanupEvent ( ) ;
855+ clearTimeout ( exitFallbackTimer ) ;
856+ this . _cleanupDetach = undefined ;
857+ } ;
858+
859+ const panel : HTMLElement = this . panel . nativeElement ;
860+ const cleanupEvent = this . _renderer . listen ( panel , 'animationend' , ( event : AnimationEvent ) => {
861+ if ( event . animationName === '_mat-select-exit' ) {
862+ this . _cleanupDetach ?.( ) ;
863+ this . _detachOverlay ( ) ;
864+ }
865+ } ) ;
859866
860- const panel : HTMLElement = this . panel . nativeElement ;
861- const cleanupEvent = this . _renderer . listen ( panel , 'animationend' , ( event : AnimationEvent ) => {
862- if ( event . animationName === '_mat-select-exit' ) {
863- this . _cleanupDetach ?.( ) ;
864- this . _overlayDir . detachOverlay ( ) ;
865- }
866- } ) ;
867+ // Since closing the overlay depends on the animation, we have a fallback in case the panel
868+ // doesn't animate. This can happen in some internal tests that do `* {animation: none}`.
869+ const exitFallbackTimer = setTimeout ( ( ) => {
870+ this . _cleanupDetach ?.( ) ;
871+ this . _detachOverlay ( ) ;
872+ } , 200 ) ;
867873
868- // Since closing the overlay depends on the animation, we have a fallback in case the panel
869- // doesn't animate. This can happen in some internal tests that do `* {animation: none}`.
870- const exitFallbackTimer = setTimeout ( ( ) => {
871- this . _cleanupDetach ?.( ) ;
872- this . _overlayDir . detachOverlay ( ) ;
873- } , 200 ) ;
874+ panel . classList . add ( 'mat-select-panel-exit' ) ;
875+ }
874876
875- panel . classList . add ( 'mat-select-panel-exit' ) ;
876- } ) ;
877+ /** Detaches the current overlay directive. */
878+ private _detachOverlay ( ) {
879+ this . _overlayDir . detachOverlay ( ) ;
880+ // Some of the overlay detachment logic depends on change detection.
881+ // Mark for check to ensure that things get picked up in a timely manner.
882+ this . _changeDetectorRef . markForCheck ( ) ;
877883 }
878884
879885 /**
0 commit comments