Components: MdSidenav should provide an option to disable the default functionality of closing the sidenav when escape is pressed

Created on 5 Jan 2017  路  4Comments  路  Source: angular/components

Currently, there is not an easy way to prevent sidenav from closing when the escape key is pressed due to the handleKeyDown method on MdSidenav.

It would be ideal to have a way to override this method, or at least be able to provide a boolean indicating that we do or do not want escape to close the sidenav.

For anyone searching for a workaround, it can be accomplished by using ViewChild and overriding the method in ngAfterViewInit (only including relevant bits in this snippet):

import { ViewChild, AfterViewInit } from '@angular/core';
import { MdSidenav } from '@angular/material';

export class SidebarComponent implements AfterViewInit {
  @ViewChild(MdSidenav) sidenav: MdSidenav;

  ngAfterViewInit() {
    this.sidenav.handleKeydown = () => {};
  }
}

Most helpful comment

include property disableClose : boolean

<md-sidenav-container>

        <md-sidenav opened mode="side" disableClose="true"   >
        <!-- sidenav content -->
        </md-sidenav>

  <!-- primary content -->
</md-sidenav-container>

All 4 comments

Sounds good! Closing this as a duplicate, then.

include property disableClose : boolean

<md-sidenav-container>

        <md-sidenav opened mode="side" disableClose="true"   >
        <!-- sidenav content -->
        </md-sidenav>

  <!-- primary content -->
</md-sidenav-container>

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitaly-t picture vitaly-t  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments

kara picture kara  路  3Comments

theunreal picture theunreal  路  3Comments

3mp3ri0r picture 3mp3ri0r  路  3Comments