You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sidenav: content area size not calculated properly with animation #9837
It looks like a change detection issue. It's not exactly ideal, but you can use the start and done handlers on the animation to start and stop a requestAnimationFrame ticker that will trigger the appropriate change detection: https://stackblitz.com/edit/angular-o5fjz1?file=app/app.component.ts
@crisbeto Any way you can think of that we can do this for people?
Reacted by KlausHans, Serge Kolchin, Itzhak, Meir Blumenfeld and Belal Safy
I'm not sure whether there's an efficient way to do it, apart from using a ResizeObserver which has pretty bad browser support. For these kinds of cases it might be better to make _updateContentMargins a part of the public API so people can trigger a recalculation manually.
With the latest Angular (Material) version the behavior changed slightly. But its still broken. https://stackblitz.com/edit/angular-kzia2e
@angular/animations7.2.9
@angular/cdk7.3.5
@angular/common7.2.9
@angular/compiler7.2.9
@angular/core7.2.9
@angular/material7.3.5
I have been having these same issues and I have not been able to find a way to animate the width change of the drawer with the current functionality of these components. This is just one thing that I don't think was taken into consideration when the autosize functionality was added. It works great as long as the width of the drawer is not animated.
The main problem I have encountered is the 'mat-drawer-transition' css class. It doesn't get added until the drawer is toggled for the first time so the content container won't animate unless the drawer has been toggled and once added it causes issues with the animations if you animate the width of the drawer. The original issue reported here is caused by this.
My temporary solution to this is to add an appropriately named directive to the MatSidenav or MatDrawer component.
This just simply removes the 'mat-drawer-transition' class and manually updates the content margins of the container. This is not ideal because it relies on implementation details (the name of the css class and the fact that it is added each time the animation starts) but it does keep this hack isolated. Doing this also means that the autosize property on the container is superfluous.
The easiest fix for this is to change the MatDrawerContainer class to add the 'mat-drawer-transition' class when the drawer animation starts and remove it when it ends. This would allow developers to handle their own functionality if they want to transition the drawer size.
Activity
mmalerba commentedon Feb 16, 2018
It looks like a change detection issue. It's not exactly ideal, but you can use the start and done handlers on the animation to start and stop a
requestAnimationFrameticker that will trigger the appropriate change detection: https://stackblitz.com/edit/angular-o5fjz1?file=app/app.component.ts@crisbeto Any way you can think of that we can do this for people?
crisbeto commentedon Feb 17, 2018
I'm not sure whether there's an efficient way to do it, apart from using a
ResizeObserverwhich has pretty bad browser support. For these kinds of cases it might be better to make_updateContentMarginsa part of the public API so people can trigger a recalculation manually.KlausHans commentedon Mar 19, 2019
With the latest Angular (Material) version the behavior changed slightly. But its still broken.
https://stackblitz.com/edit/angular-kzia2e
@angular/animations7.2.9
@angular/cdk7.3.5
@angular/common7.2.9
@angular/compiler7.2.9
@angular/core7.2.9
@angular/material7.3.5
robert-king commentedon Nov 21, 2019
I'm facing a similar issue - I adjust the width of the side-nav from 200 to 79 pixels:
sidenav component sets its width internally with hostbinding:
but mat-sidenav-content margin-left stays at 200px when the side-nav changes to 79px. It makes collapsing the side-nav redundant.
robert-king commentedon Nov 24, 2019
Here's my temporary fix:
KlausHans commentedon Mar 27, 2020
Still broken.
https://stackblitz.com/edit/angular-rf4mmn
meblum commentedon May 20, 2020
Any updates on this?
empinator commentedon May 18, 2021
this workaround with setTimeout worked for me
Source: #6743 (comment)
andrewalderson commentedon Dec 21, 2021
I have been having these same issues and I have not been able to find a way to animate the width change of the drawer with the current functionality of these components. This is just one thing that I don't think was taken into consideration when the
autosizefunctionality was added. It works great as long as the width of the drawer is not animated.The main problem I have encountered is the 'mat-drawer-transition' css class. It doesn't get added until the drawer is toggled for the first time so the content container won't animate unless the drawer has been toggled and once added it causes issues with the animations if you animate the width of the drawer. The original issue reported here is caused by this.
My temporary solution to this is to add an appropriately named directive to the MatSidenav or MatDrawer component.
This just simply removes the 'mat-drawer-transition' class and manually updates the content margins of the container. This is not ideal because it relies on implementation details (the name of the css class and the fact that it is added each time the animation starts) but it does keep this hack isolated. Doing this also means that the
autosizeproperty on the container is superfluous.The easiest fix for this is to change the MatDrawerContainer class to add the 'mat-drawer-transition' class when the drawer animation starts and remove it when it ends. This would allow developers to handle their own functionality if they want to transition the drawer size.