I'm writing here since I have a question about Mat Toolbar and Mat-sidenav from Angular Material. I'm trying to get the Sidenav to go under the toolbar and the toolbar always occupies the top part, something like this:
Example
Here´s my code:
<mat-sidenav-container class="sidenav-container" autosize>
<mat-sidenav #drawer class="sidenav" fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'side' : 'push'"
[opened]="(isHandset$ | async)">
<mat-toolbar class="fixed-header">
<img class="logooTest" src="data:image/gif;base64,test"/>
</mat-toolbar>
<mat-nav-list>
<mat-list-item>
<a routerLink="/dashboard">Test</a>
<mat-icon mat-list-icon>home</mat-icon>
</mat-list-item>
<mat-list-item>
<a routerLink="/dashboard">Test</a>
<mat-icon mat-list-icon>home</mat-icon>
</mat-list-item>
<mat-list-item>
<a routerLink="/test">Test</a>
<mat-icon mat-list-icon>tune</mat-icon>
</mat-list-item>
<mat-list-item>
<a routerLink="/#">Test</a>
<mat-icon mat-list-icon>settings</mat-icon>
</mat-list-item>
<mat-list-item>
<a routerLink="/#">Test</a>
<mat-icon mat-list-icon>layers</mat-icon>
</mat-list-item>
<mat-list-item (click)="showSubmenu = !showSubmenu" class="parent">
<span class="full-width" *ngIf="isExpanded || isShowing">Test dropdown</span>
<mat-icon mat-list-icon>flash_on</mat-icon>
<mat-icon class="menu-button" [ngClass]="{'rotated' : showSubmenu}" *ngIf="isExpanded || isShowing">expand_more</mat-icon>
</mat-list-item>
<div class="submenu" [ngClass]="{'expanded' : showSubmenu}" *ngIf="isShowing || isExpanded">
<mat-list-item>
<a routerLink="/#">Test</a>
</mat-list-item>
<mat-list-item>
<a routerLink="/#">Test</a>
</mat-list-item>
<h2 matSubheader><mat-icon>account_balance</mat-icon> Test</h2>
<mat-list-item (click)="showSubSubMenu = !showSubSubMenu" class="parent">
<span class="full-width" *ngIf="isExpanded || isShowing">Test</span>
<mat-icon class="menu-button" [ngClass]="{'rotated' : showSubSubMenu}" *ngIf="isExpanded || isShowing">expand_more</mat-icon>
</mat-list-item>
<div class="submenu" [ngClass]="{'expanded' : showSubSubMenu}" *ngIf="isShowing || isExpanded">
<mat-list-item>
<a routerLink="/test">Test</a>
</mat-list-item>
<mat-list-item>
<a routerLink="/#">Test</a>
</mat-list-item>
<h2 matSubheader><mat-icon>card_travel</mat-icon> Test</h2>
<mat-list-item>
<a routerLink="/#">Test</a>
</mat-list-item>
<mat-list-item>
<a routerLink="/#">Test</a>
</mat-list-item>
</div>
</div>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary" class="mat-elevation-z5">
<button
type="button"
aria-label="Toggle sidenav"
mat-icon-button
(click)="drawer.toggle()">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span class="spacer"></span>
<div class="navigation">
<a class="button" href="">
<mat-icon class="logoutIcon">exit_to_app</mat-icon>
<div class="logout"><span class="aligned-with-icon">Salir</span></div>
</a>
</div>
</mat-toolbar>
</mat-sidenav-content>
</mat-sidenav-container>
I'm using the version 5.6.0 of Angular and Angular Material. I tried using CSS and also changing the order of the structure of the code, but this last one simply gave me errors and more errors; preventing the application from running.
To set up a sidenav we use three components: <mat-sidenav-container> which acts as a structural container for our content and sidenav, <mat-sidenav-content> which represents the main content, and <mat-sidenav> which represents the added side content.
The <mat-toolbar> is an Angular Directive used to create a toolbar to show the title, header, or any button action of buttons. <mat-toolbar>: It represents the main container. <mat-toolbar-row>: It adds a new row at the toolbar. Example of ToolBar: ADVERTISEMENT.
The color of a <mat-toolbar> can be changed by using the color property. By default, toolbars use a neutral background color based on the current theme (light or dark). This can be changed to 'primary' , 'accent' , or 'warn' .
The <mat-sidenav>, an Angular Directive, is used to create a side navigation bar and main content panel with material design styling and animation capabilities. <mat-sidenav-container> - Represents the main container.
for me just change the html like G. Tranter and set the fixedInViewport
in the mat-sidenav from true
to false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With