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
md-sidenav: make it automatically responsive #1130
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/sidenavfeatureLabel used to distinguish feature request from other issues
Feature request
Version: Angular Material 2.0.0-alpha.7 wax-umpire
I'd like to have an option where the sidenav can be responsive automatically, by having a breakpoint where the sidenav is shown by default when the width is higher than X.
Is there any plan to have this? I could submit a PR if this is wanted.
Reacted by Sebastian, Camilo Azula, Gary Chamberlain, maltehol, Benedek Elek-Zalán, Jason Yeomans, Daniele A, Michael Sullivan, Artjom Zabelin, ertl and 7 more
Is this doable for now? I really like the menu being locked open like Alex stated. Just added this to app.component.ts till this is supported. I'm new to Angular in general.
In your component, add a responsive handler for link click:
onLinkClick():void {
if (this.isMobileView) {
this.menuSidenav.close();
}
}
The onLinkClick() handler needs to added to each of the menu links in your template.
It will close the menu after clicking a link, but not when the menu should stay open.
In your template, bind the md-sidenav's "mode", "opened", and "disableClose" attributes to your component's responsive boolean.
The sidenav will be in the correct state at the initial view.
The sidenav mode will change from "side" to "over".
The sidenav will automatically open or close.
The disableClose prevents closing with the escape key.
Reacted by Paul de Rosanbo, skirjak, Sandeep Rao, Allan Roy Balderama, Aaron Storck, Jean, Souhaila Merghad, Andrew Eckart, Rafael Morais, Natalie Perret and 11 more
Reacted by Robouste, Michael Clark, 两米, Ruben Rodriguez Aparicio and Stephen Gardner
Very nice answer, (the one about FlexLayoutModule). But FlexLayoutModule docs are as clear as mud. So could you please be a bit more specific here:
what types are:
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/sidenavfeatureLabel used to distinguish feature request from other issues
Activity
jelbourn commentedon Aug 31, 2016
We definitely plan to do this- so far we haven't yet dove into all of the responsive behaviors for various components.
GaryChamberlain commentedon Oct 18, 2016
It would be great if it worked like the left sidebar in the Firebase console.
sikemullivan commentedon Nov 16, 2016
Is this doable for now? I really like the menu being locked open like Alex stated. Just added this to app.component.ts till this is supported. I'm new to Angular in general.
` @ViewChild("start") private start: MdSidenav;
constructor(private _ngZone: NgZone) { }
ngOnInit() {
//Total hack
window.onresize = (e) => {
this.checkMenu();
};
this.checkMenu();
}
checkMenu() {
this._ngZone.run(() => {
var w = window.innerWidth;
if (w > 768) {
this.start.open();
} else {
this.start.close();
}
});
}`
alexjoverm commentedon Nov 17, 2016
I did it in the FRP + Redux way (but of course you can ommit the Redux stuff). In case you wanna check it out: https://github.com/alexjoverm/Footle/blob/master/client/src/app/containers/sidenav/sidenav.component.ts
pauldemarco commentedon Dec 8, 2016
sikemullivan, that totally works, have you noticed any compatibility issues?
krisklosterman commentedon Mar 23, 2017
This seems to work too:
Another idea
HTML
ajaysattikar commentedon Apr 19, 2017
That's perfect, thanks!!
However I was wondering if there any solution for "sidenav collapse to show icons".
Gusachenko commentedon Apr 29, 2017
Here's another way, with latest
Renderer2module:angularexample commentedon May 8, 2017
Here are 2 ways to make mdsidenav responsive automatically.
In your component,
In your component, add a responsive handler for link click:
The onLinkClick() handler needs to added to each of the menu links in your template.
It will close the menu after clicking a link, but not when the menu should stay open.
In your template, bind the md-sidenav's "mode", "opened", and "disableClose" attributes to your component's responsive boolean.
Now, based on your responsive breakpoint...
Denis-Frolov commentedon May 19, 2017
Very nice answer, (the one about FlexLayoutModule). But FlexLayoutModule docs are as clear as mud. So could you please be a bit more specific here:
what types are:
jawadst commentedon May 27, 2017
@Denis-Frolov
They have a complete API doc with an example and the right types here: https://github.com/angular/flex-layout/wiki/ObservableMedia
Denis-Frolov commentedon May 27, 2017
@jawadst
Oh thanks, I did not see that one.