-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sidenav): add disableClose option #2501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,12 @@ export class MdSidenav implements AfterContentInit { | |
/** Mode of the sidenav; whether 'over' or 'side'. */ | ||
@Input() mode: 'over' | 'push' | 'side' = 'over'; | ||
|
||
/** Whether the sidenav can be closed with the escape key or not. */ | ||
@Input() | ||
get disableClose(): boolean { return this._disableClose; } | ||
set disableClose(value: boolean) { this._disableClose = coerceBooleanProperty(value); } | ||
private _disableClose: boolean = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While you're doing this, can you also change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jelbourn Made the changes you requested. |
||
|
||
/** Whether the sidenav is opened. */ | ||
_opened: boolean = false; | ||
|
||
|
@@ -233,7 +239,7 @@ export class MdSidenav implements AfterContentInit { | |
* @docs-private | ||
*/ | ||
handleKeydown(event: KeyboardEvent) { | ||
if (event.keyCode === ESCAPE) { | ||
if (event.keyCode === ESCAPE && !this.disableClose) { | ||
this.close(); | ||
event.stopPropagation(); | ||
} | ||
|
@@ -328,7 +334,7 @@ export class MdSidenavContainer implements AfterContentInit { | |
get end() { return this._end; } | ||
|
||
/** Event emitted when the sidenav backdrop is clicked. */ | ||
@Output('backdrop-clicked') onBackdropClicked = new EventEmitter<void>(); | ||
@Output() backdropClick = new EventEmitter<void>(); | ||
|
||
/** The sidenav at the start/end alignment, independent of direction. */ | ||
private _start: MdSidenav; | ||
|
@@ -435,17 +441,15 @@ export class MdSidenavContainer implements AfterContentInit { | |
} | ||
|
||
_onBackdropClicked() { | ||
this.onBackdropClicked.emit(); | ||
this.backdropClick.emit(); | ||
this._closeModalSidenav(); | ||
} | ||
|
||
_closeModalSidenav() { | ||
if (this._start != null && this._start.mode != 'side') { | ||
this._start.close(); | ||
} | ||
if (this._end != null && this._end.mode != 'side') { | ||
this._end.close(); | ||
} | ||
// Close all open sidenav's where closing is not disabled and the mode is not `side`. | ||
[this._start, this._end] | ||
.filter(sidenav => sidenav && !sidenav.disableClose && sidenav.mode !== 'side') | ||
.forEach(sidenav => sidenav.close()); | ||
} | ||
|
||
_isShowingBackdrop(): boolean { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxime1992 The solution to our problem : backdropClick