question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MdSidenav] - Sidenav Resizing Regression

See original GitHub issue

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.

example

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);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:26
  • Comments:42 (7 by maintainers)

github_iconTop GitHub Comments

12reactions
mmalerbacommented, Oct 28, 2017

I definitely think we need to do something about this, even if its just making some of these methods public so people can trigger update manually. Raising the priority.

12reactions
ghwyfcommented, Sep 11, 2017

Here is my solution: HTML

<md-sidenav-container #container>
    <md-sidenav  mode="side" opened="{{showMenu}}" class="shadow"></md-sidenav>
    <div class="my-content"></div>
</md-sidenav-container>

TS

export class MyComponent implements OnInit, AfterViewInit {
    @ViewChild('container') private _container;
    public showMenu: boolean = false;
    ...
    ngAfterViewInit() {
      setTimeout(()=>{
        this.showMenu = true;
      },0);
      this._container._ngZone.onMicrotaskEmpty.subscribe(() => {
        this._container._updateStyles();
        this._container._changeDetectorRef.markForCheck();
      })
    };
    ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

material angular sidenav trigger resize - Stack Overflow
The trick is to set autosize to true when you know you are going to change the size of the sidenav and turn...
Read more >
Sidenav - Angular Material
Resizing an open sidenav. By default, Material will only measure and resize the drawer container in a few key moments (on open, on...
Read more >
angular-material | Yarn - Package Manager
This repository was used to publish the AngularJS Material v1.x library and localized installs using npm . You can find the component source-code...
Read more >
Angular window resize event - Stack Overflow
I would like to perform some tasks based on the window re-size event (on load and dynamically). Currently I have my DOM as...
Read more >
how to toggle div using another component angular - You.com
Sidemenu @ViewChild('start') sidenav: MdSidenav;. where start is the name of the component you want to reference, in this case the sidenav.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found