Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/angular/components/llms.txt

Use this file to discover all available pages before exploring further.

MatSidenav

The mat-sidenav is a collapsible side content component that can display navigation or any custom content. It supports three display modes: over, push, and side.

Basic Usage

import { MatSidenavModule } from '@angular/material/sidenav';
import { MatButtonModule } from '@angular/material/button';

@Component({
  selector: 'sidenav-example',
  imports: [MatSidenavModule, MatButtonModule],
  template: `
    <mat-sidenav-container>
      <mat-sidenav #sidenav mode="side" opened>
        <p>Sidenav content</p>
      </mat-sidenav>

      <mat-sidenav-content>
        <button mat-button (click)="sidenav.toggle()">Toggle</button>
        <p>Main content</p>
      </mat-sidenav-content>
    </mat-sidenav-container>
  `,
  styles: [`
    mat-sidenav-container {
      height: 100%;
    }
    mat-sidenav {
      width: 250px;
    }
  `]
})
export class SidenavExample {}

API Reference

MatSidenav

Selector: mat-sidenav Extends: MatDrawer

Inputs

NameTypeDefaultDescription
position'start' | 'end''start'The side that the drawer is attached to
mode'over' | 'push' | 'side''over'Mode of the drawer
openedbooleanfalseWhether the drawer is opened
disableClosebooleanfalseWhether the drawer can be closed with the escape key or by clicking on the backdrop
autoFocusAutoFocusTarget | string | boolean-Whether the drawer should focus the first focusable element automatically when opened
fixedInViewportbooleanfalseWhether the sidenav is fixed in the viewport
fixedTopGapnumber0The gap between the top of the sidenav and the top of the viewport when in fixed mode
fixedBottomGapnumber0The gap between the bottom of the sidenav and the bottom of the viewport when in fixed mode

Outputs

NameTypeDescription
openedChangeEventEmitter<boolean>Event emitted when the drawer open state is changed
openedObservable<void>Event emitted when the drawer has been opened
closedObservable<void>Event emitted when the drawer has been closed
openedStartObservable<void>Event emitted when the drawer has started opening
closedStartObservable<void>Event emitted when the drawer has started closing
positionChangedEventEmitter<void>Event emitted when the drawer’s position changes

Methods

MethodReturnsDescription
open(openedVia?: FocusOrigin)Promise<MatDrawerToggleResult>Open the drawer
close()Promise<MatDrawerToggleResult>Close the drawer
toggle(isOpen?: boolean, openedVia?: FocusOrigin)Promise<MatDrawerToggleResult>Toggle the drawer

MatSidenavContainer

Selector: mat-sidenav-container

Inputs

NameTypeDefaultDescription
autosizebooleanfalseWhether to automatically resize the container whenever the size of any of its drawers changes
hasBackdropboolean | null-Whether the drawer container should have a backdrop

Outputs

NameTypeDescription
backdropClickEventEmitter<void>Event emitted when the drawer backdrop is clicked

Methods

MethodDescription
open(): voidCalls open of both start and end drawers
close(): voidCalls close of both start and end drawers
updateContentMargins(): voidRecalculates and updates the inline styles for the content

Properties

PropertyTypeDescription
startMatSidenav | nullThe drawer child with the start position
endMatSidenav | nullThe drawer child with the end position
scrollableCdkScrollableReference to the CdkScrollable instance that wraps the scrollable content

MatSidenavContent

Selector: mat-sidenav-content Provides scrollable content area within the sidenav container.

MatDrawer

Selector: mat-drawer Base drawer component that MatSidenav extends.

Examples

Responsive Navigation

import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';

@Component({
  template: `
    <mat-sidenav-container>
      <mat-sidenav 
        #sidenav 
        [mode]="isHandset ? 'over' : 'side'"
        [opened]="!isHandset">
        <mat-nav-list>
          <a mat-list-item href="#">Home</a>
          <a mat-list-item href="#">About</a>
          <a mat-list-item href="#">Contact</a>
        </mat-nav-list>
      </mat-sidenav>

      <mat-sidenav-content>
        <button mat-icon-button (click)="sidenav.toggle()" *ngIf="isHandset">
          <mat-icon>menu</mat-icon>
        </button>
        <router-outlet></router-outlet>
      </mat-sidenav-content>
    </mat-sidenav-container>
  `
})
export class ResponsiveNavExample {
  isHandset = false;

  constructor(private breakpointObserver: BreakpointObserver) {
    this.breakpointObserver
      .observe([Breakpoints.Handset])
      .subscribe(result => {
        this.isHandset = result.matches;
      });
  }
}

Fixed Sidenav

@Component({
  template: `
    <mat-sidenav-container>
      <mat-sidenav 
        mode="side" 
        opened 
        fixedInViewport
        [fixedTopGap]="64"
        [fixedBottomGap]="0">
        Navigation with fixed position
      </mat-sidenav>

      <mat-sidenav-content>
        Main content that scrolls independently
      </mat-sidenav-content>
    </mat-sidenav-container>
  `
})
export class FixedSidenavExample {}

Dual Sidenav

@Component({
  template: `
    <mat-sidenav-container>
      <mat-sidenav position="start" mode="side" opened>
        Left sidenav
      </mat-sidenav>

      <mat-sidenav position="end" mode="side" opened>
        Right sidenav
      </mat-sidenav>

      <mat-sidenav-content>
        Content with both left and right sidebars
      </mat-sidenav-content>
    </mat-sidenav-container>
  `
})
export class DualSidenavExample {}

Sidenav with Custom Backdrop

@Component({
  template: `
    <mat-sidenav-container [hasBackdrop]="true">
      <mat-sidenav #sidenav mode="over">
        Sidenav content
      </mat-sidenav>

      <mat-sidenav-content>
        <button mat-button (click)="sidenav.open()">Open with Backdrop</button>
      </mat-sidenav-content>
    </mat-sidenav-container>
  `
})
export class BackdropSidenavExample {}

Display Modes

Over

The sidenav floats over the main content and is usually accompanied by a backdrop:
<mat-sidenav mode="over" opened>

Push

The sidenav pushes the main content to make room for itself:
<mat-sidenav mode="push" opened>

Side

The sidenav sits side-by-side with the main content, shrinking the content to make room:
<mat-sidenav mode="side" opened>

Accessibility

Keyboard Interaction

  • ESCAPE: Closes the drawer when disableClose is false
  • TAB: Moves focus through interactive elements within the drawer

ARIA

The sidenav has role="navigation" by default. The drawer has tabindex="-1" for focus management.

Focus Management

By default, when a sidenav opens:
  • In side mode, focus stays on the triggering element
  • In over or push mode, focus moves to the first focusable element in the sidenav
When closed, focus returns to the element that opened it.

Styling

The sidenav container must have an explicit height:
mat-sidenav-container {
  height: 100vh;
}

mat-sidenav {
  width: 280px;
  padding: 16px;
}

mat-sidenav-content {
  padding: 16px;
}

Types

MatDrawerMode

type MatDrawerMode = 'over' | 'push' | 'side';

MatDrawerToggleResult

type MatDrawerToggleResult = 'open' | 'close';

AutoFocusTarget

type AutoFocusTarget = 'dialog' | 'first-tabbable' | 'first-heading';

Injection Tokens

MAT_DRAWER_DEFAULT_AUTOSIZE

const MAT_DRAWER_DEFAULT_AUTOSIZE: InjectionToken<boolean>;
Configures whether drawers should use auto sizing by default:
providers: [
  {
    provide: MAT_DRAWER_DEFAULT_AUTOSIZE,
    useValue: true
  }
]