Skip to content

bug(MatDrawer): Resizing drawer after 'mat-drawer-transition' class added causes animation lag #24119

@andrewalderson

Description

@andrewalderson

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Currently the MatDrawer component is able to resize the content when the size of the drawer changes. This works great unless you add an animation to the drawer's width after the 'mat-drawer-transition' class has been added to the drawer container. After the class has been added the animation for the drawer content lags behind the animation for the drawer width.

Currently all of the hacks and work arounds I have seen for this behavior don't take into account resizing after the drawer has been toggled open and closed. Toggling the drawer adds a class called 'mat-drawer-transition' to the drawer container in the _watchDrawerToggle method of MatDrawerContainer. This class adds the css transitions for the drawer content and backdrop and these animations seem to cause the issue. Also setting the autosize property on the drawer container does nothing in this instance.

In the sample I provided I use an inner component in the drawer to do the resizing. This encapsulates the behavior and causes the drawer itself to resize. I also use a ResizeObserver (because it is almost 2022 and we don't support IE anymore) to update the content margins continually during the width animation. I have also not used the autosize property on the drawer container because it doesn't do anything to fix the issue and the content margins are being updated during the width animation.

In my experiments removing the 'mat-drawer-transition' class after the drawer open/close animation completes fixes the issue.

Reproduction

Stackblitz of the issue is here: https://stackblitz.com/edit/angular-ivy-ftfajt?file=src%2Fapp%2Fapp.component.ts
Steps to reproduce:

  1. Launch the Stackblitz sample
  2. Toggle the size of the drawer with the arrow icon at the top of the drawer - Animation works correctly
  3. Toggle the drawer open and closed with the menu icon at the top of the content - Animation works correctly
  4. Repeat step 2 - Animation for the content left margin lags behind the animation for the drawer.

To see it working properly uncomment the code in the AppComponent openChanged method and run steps again.

Expected Behavior

The animation for the drawer should not lag behind the animation for the content.

Actual Behavior

The animation for the content lags behind the animation for the drawer when the 'mat-drawer-transition' class is present on the MatDrawerContainer.

Environment

  • Angular: 13.1.1
  • CDK/Material: 13.1.1
  • Browser(s): Edge (Chromium) 96.0.1054.57
  • Operating System: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: material/sidenavneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions