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 = () => {};
}
}
Should be taken care of with https://github.com/angular/material2/pull/2501.
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._
Most helpful comment
include property disableClose : boolean