I have a sidenav and a nested toolbar
toolbar.html
<md-sidenav-container fullscreen>
<md-sidenav #sidenav mode="side" color="primary">
<md-toolbar color="primary"><span>Sidenav</span></md-toolbar>
<button md-button class="sidenav-link" (click)="sidenav.close()">
<md-icon>home</md-icon><span class="title"> HOME</span>
</button>
<button md-button class="sidenav-link" (click)="sidenav.close()">
<md-icon>home</md-icon><span class="title"> HOME</span>
</button>
</md-sidenav>
<app-toolbar [sidenav]="sidenav"></app-toolbar>
</md-sidenav-container>
sidenav.html
<md-toolbar color="primary">
<button md-button class="toolbar-menu-button"
(click)="sidenav.toggle(); isCollapsed = !isCollapsed">
<md-icon [@iconChange]="isCollapsed">menu</md-icon>
</button>
<span class="toolbar-spacer"></span>
<button md-button class="toolbar-link" >DASHBOARD</button>
<span class="toolbar-spacer"></span>
</md-toolbar>
https://plnkr.co/edit/up19ZNJyMt6uatqdI9uv?p=preview
I would like to close the sidenav up to the home icon like Navigation Drawer
This can be achieved using a simple css hack. We can call methods increase() and decrease() that changes the width of sidenav based on some event like mouseenter and mouseleave or in your case onClick of "toolbar-menu-button"
This will incerese the width of sidenav when we point on sidenav and decrease the width when we point the mouse pointer at some other place.
Have a look at this demo :- https://mini-sidenav.firebaseapp.com/
and the github repo :- https://github.com/Ravi-Rajpurohit/mini-md-sidenav
I hope this helps :-)
This problem is little unusual. Since the button from toolbar is controlling the open and close state, I had to add an
EventListener
to pass the state ofsidenav
whenever the button is clicked.Based on the
event
flag, I added somengStyle
that will maintain the width ofsidenav
. Note that, thesidenav
is always open now [add propertyopened="true"
], since it's always visible. I also ended up using the emitted flag from toolbar to use for 'Sidenav' title. You can remove it if you need to show the partial 'Sid'.Also, since the sidenav is always open, I added custom css to animate the change of width.
Plunker demo
toolbar.component.ts:
toolbar.component.html:
sidenav.component.ts:
sidenav.component.html:
sidenav.component.css:
Hope this helps you :)