Repository navigation
Description
Bug, feature request, or proposal:
Bug/Regression from 2.0.0-beta.8.
Also a feature request for an API to allow triggering recalculations for the MdSidenavContainer/MdDrawerContainer, or being able to update _styles manually and having the view update..
What is the expected behavior?
In the previous release 2.0.0-beta.8 the sidenav resized when the window was resized.
I have a responsive sidenav that uses Angular flex-layout for showing/hiding responsive content in the sidenav when the view changes from md to lg and vice-versa.
What is the current behavior?
In 2.0.0-beta.10 this is no longer the case. The changes made in #6189 made the sidenav update only when the sidenav is opening/closing.
Since flex-layout's changes occur without having to call open() or close() on the sidenav, the width recalculation doesn't occur.
What are the steps to reproduce?
Put dynamic/responsive content within a sidenav that is configured with "side".
What is the use-case or motivation for changing an existing behavior?
Being able to dynamically call a refresh of the MdSidenav/MdDrawer or MdSidenavContainer/MdDrawerContainer.
Even better would be an accessor to allow manually setting the margin of the sidenav to allow for pre-computing the _style variable and updating it when needed.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 4.3.5
Angular Material 2.0.0-beta.10
Is there anything else we should know?
This is similar to #6583.
For right now I am using the following hack in my navigation directive to workaround whenever the ObservableMedia from angular flex-layout changes:
// Timeout required for flex-layout directives to update the child views/the width.
setTimeout(() => {
(this._container as any)._updateStyles();
(this._container as any)._changeDetectorRef.markForCheck();
}, 0);

Activity
fix(layout-docs): workaround for now since MdSidenav has issues when …
chore(): upgrade to material/cdk@beta.10 (#847)
djfishe commentedon Sep 4, 2017
+1. Same issue I have after upgrading to 2.0.0-beta.10
sbeaufort commentedon Sep 6, 2017
Same issue after upgrading from 2.0.0-beta.8 to 2.0.0-beta.10
My workarround :
app.component.html
<md-sidenav class="main-sidenav" #sidenav mode="side" opened="false">app.component.ts
bleuscyther commentedon Sep 6, 2017
that is exactly what i did @sbeaufort. It creates a small animation at the first page load but its ok
AppField commentedon Sep 10, 2017
I have the exact same issue.
ghwyf commentedon Sep 11, 2017
Here is my solution:
HTML
TS
AppField commentedon Sep 11, 2017
@ghwyf Thank you very much! This workaround also worked for me.
benfontan commentedon Sep 20, 2017
Same issue for me upgrading to 2.0.0-beta.10.
I used @ghwyf fix which works perfectly, thank you.
josephperrott commentedon Sep 27, 2017
Closing as duplicate of #1130
upstreamosGH commentedon Sep 28, 2017
Join the responses of @angularexample in #1130 and @ghwyf here, works for me.
ngAfterViewInit seems too heavy for my application so I replace it with a specific call only when Subscription happens.
adrm commentedon Sep 28, 2017
@josephperrott I think the issues are about different things. The one you referenced is about opening and closing the sidenav automatically when viewport width changes. This one is about being able to resize the sidenav width while keeping it open.
Before the last update this worked with no problem. Right now, the main content is not being resized when the sidebar width is resized. Some people have shared workarounds for this, but I think it would be nice if Angular Material would support this use case which is quite popular in places like firebase.
josephperrott commentedon Sep 28, 2017
Reopening, sorry I misunderstood a bit there.
34 remaining items
crisbeto commentedon Dec 5, 2017
@axtho what these changes do is allow you to opt in to having the drawer container resize once per change detection cycle, rather than on open/close.
axtho commentedon Dec 5, 2017
@crisbeto so it is correct to assume that I would need to trigger change detection after running an animation when the component is on OnPush?
crisbeto commentedon Dec 5, 2017
You might not have to since the sidenav will check inside
ngDoCheckwhich keeps firing not matter the change detection strategy.gerardcarbo commentedon Oct 1, 2018
Still happening in 6.4.7:
ojpbay commentedon Oct 11, 2018
Yep still an issue in 6.4.7
"@angular/material": "^6.4.7"kflo commentedon Oct 19, 2018
Come on, wheres the fix...?
aribrick commentedon Oct 19, 2018
Same. This is still an issue in 6.4.7
brookesouza commentedon Oct 19, 2018
This solution is still a bit of a hack, but it's less of a hack than setTimeout...
bobbydowling commentedon Nov 3, 2018
this.sidenavContainer.autosize = true;
worked for me... after mucking with it for an hour. :(
rb-mwindh commentedon Nov 5, 2018
I observed the same issue in 6.4.7, but only in certain cases:
When debugging the sourcecode of MatSidenavContainer, I recognized the code being executed to look like the source code of the 5.2.x branch
(line 713): this._ngZone.run(() => this._contentMargins.next({left, right}));instead of
(line 717): this._ngZone.run(() => this._contentMarginChanges.next(this._contentMargins));Finally I identified the buildOptimizer cache as the culprit. After deleting
<project>/node_modules/@angular-devkit/build-optimizer/src/.cacheeverything worked like a charm.FirstVertex commentedon Feb 6, 2019
@dereekb this issue should not be closed.
Still exists in the year 2019.
@bobbydowling solution is the only thing worked for me. And I mucked with it for like 3 hours.
MeghnathDas commentedon May 15, 2019
Where did you put autoSize = true ?
I have tried to put in OnInit() and AfterViewInit() but it didn't worked.
FirstVertex commentedon May 15, 2019
@MeghnathDas here is documentation of
autosizeflag. It is option ofmat-drawer-containerhttps://material.angular.io/components/sidenav/api#MatDrawerContainer
HTH
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.