@@ -364,7 +364,6 @@ export class MatDrawer implements AfterViewInit, OnDestroy {
364364 } ) ;
365365 }
366366 } ) ,
367- renderer . listen ( element , 'transitionrun' , this . _handleTransitionEvent ) ,
368367 renderer . listen ( element , 'transitionend' , this . _handleTransitionEvent ) ,
369368 renderer . listen ( element , 'transitioncancel' , this . _handleTransitionEvent ) ,
370369 ] ;
@@ -568,17 +567,24 @@ export class MatDrawer implements AfterViewInit, OnDestroy {
568567
569568 this . _opened . set ( isOpen ) ;
570569
571- if ( this . _container ?. _transitionsEnabled ) {
572- // Note: it's important to set this as early as possible,
573- // otherwise the animation can look glitchy in some cases.
574- this . _setIsAnimating ( true ) ;
575- } else {
576- // Simulate the animation events if animations are disabled.
577- setTimeout ( ( ) => {
578- this . _animationStarted . next ( ) ;
579- this . _animationEnd . next ( ) ;
580- } ) ;
581- }
570+ this . _ngZone . runOutsideAngular ( ( ) => {
571+ if ( this . _container ?. _transitionsEnabled ) {
572+ // Note: it's important to set this as early as possible,
573+ // otherwise the animation can look glitchy in some cases.
574+ this . _setIsAnimating ( true ) ;
575+
576+ // Previously we dispatched this in a `transitionrun` event, but it might not fire
577+ // if the element is hidden (see #32992). Since this event is load-bearing for the
578+ // margin calculations, we need it to fire consistently.
579+ setTimeout ( ( ) => this . _animationStarted . next ( ) ) ;
580+ } else {
581+ // Simulate the animation events if animations are disabled.
582+ setTimeout ( ( ) => {
583+ this . _animationStarted . next ( ) ;
584+ this . _animationEnd . next ( ) ;
585+ } ) ;
586+ }
587+ } ) ;
582588
583589 this . _elementRef . nativeElement . classList . toggle ( 'mat-drawer-opened' , isOpen ) ;
584590
@@ -646,17 +652,13 @@ export class MatDrawer implements AfterViewInit, OnDestroy {
646652
647653 if ( event . target === element ) {
648654 this . _ngZone . run ( ( ) => {
649- if ( event . type === 'transitionrun' ) {
650- this . _animationStarted . next ( event ) ;
651- } else {
652- // Don't toggle the animating state on `transitioncancel` since another animation should
653- // start afterwards. This prevents the drawer from blinking if an animation is interrupted.
654- if ( event . type === 'transitionend' ) {
655- this . _setIsAnimating ( false ) ;
656- }
657-
658- this . _animationEnd . next ( event ) ;
655+ // Don't toggle the animating state on `transitioncancel` since another animation should
656+ // start afterwards. This prevents the drawer from blinking if an animation is interrupted.
657+ if ( event . type === 'transitionend' ) {
658+ this . _setIsAnimating ( false ) ;
659659 }
660+
661+ this . _animationEnd . next ( event ) ;
660662 } ) ;
661663 }
662664 } ;
@@ -941,6 +943,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
941943 * is properly hidden.
942944 */
943945 private _watchDrawerToggle ( drawer : MatDrawer ) : void {
946+ //
944947 drawer . _animationStarted . pipe ( takeUntil ( this . _drawers . changes ) ) . subscribe ( ( ) => {
945948 this . updateContentMargins ( ) ;
946949 this . _changeDetectorRef . markForCheck ( ) ;
0 commit comments