Skip to content

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

@s992

Description

@s992

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 = () => {};
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions