Angular Material SideNav autosize not working

Discussão em 'Angular' iniciado por B.Cos, Abril 30, 2025.

  1. B.Cos

    B.Cos Guest

    I was using Angular Material to build a sidenav that can hide the nav text when onclick menu. I follow the https://material.angular.io/components/sidenav/overview using autosize on mat-sidenav-container

    But the sidenav still overlay the mat-sidenav-content part and it doesn't auto resize the content part

    I using "@angular/material": "^8.0.2"

    [​IMG] [​IMG]

    html

    <mat-sidenav-container class="example-container" autosize>
    <mat-sidenav #sidenav class="example-sidenav" mode="side" opened="true">

    <mat-nav-list>
    <mat-list-item>
    <button mat-icon-button (click)="isExpanded = !isExpanded">
    <mat-icon *ngIf="!isExpanded">chevron_right</mat-icon>
    <mat-icon *ngIf="isExpanded">chevron_left</mat-icon>
    </button>
    </mat-list-item>
    <mat-list-item>
    <mat-icon mat-list-icon>home</mat-icon>
    <p matLine *ngIf="isExpanded">Home</p>
    </mat-list-item>
    </mat-nav-list>
    </mat-sidenav>
    <mat-sidenav-content>

    Main content

    </mat-sidenav-content>

    </mat-sidenav-container>


    ts file

    import {Component} from '@angular/core';
    import { MatSidenav } from '@angular/material/sidenav';

    @Component({
    selector: 'sidenav-autosize-example',
    templateUrl: 'sidenav-autosize-example.html',
    styleUrls: ['sidenav-autosize-example.css'],
    })
    export class SidenavAutosizeExample {
    isExpanded = false;
    }


    css

    .example-container {
    width: 100%;
    height: 300px;
    border: 1px solid rgba(0, 0, 0, 0.5);
    }

    .example-sidenav-content {
    padding: 10px;
    height: 100%;
    }

    Continue reading...

Compartilhe esta Página