mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(dialog): unable to press escape to close in lazy-loaded module (#3788)
Fixes not being able to use the escape key to close a dialog that was opened from a lazy-loaded module. Fixes #3737.
This commit is contained in:
committed by
Jeremy Elbourn
parent
033fe8db75
commit
3796f69f9d
@@ -127,7 +127,6 @@ describe('MdDialog', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should close a dialog via the escape key', async(() => {
|
||||
dialog.open(PizzaMsg, {
|
||||
viewContainerRef: testViewContainerRef
|
||||
@@ -585,6 +584,17 @@ describe('MdDialog with a parent MdDialog', () => {
|
||||
.toBe('', 'Expected closeAll on parent MdDialog to close dialog opened by child');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should close the top dialog via the escape key', async(() => {
|
||||
childDialog.open(PizzaMsg);
|
||||
|
||||
dispatchKeyboardEvent(document, 'keydown', ESCAPE);
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(overlayContainerElement.querySelector('md-dialog-container')).toBeNull();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export class MdDialog {
|
||||
let dialogRef =
|
||||
this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config);
|
||||
|
||||
if (!this._openDialogs.length && !this._parentDialog) {
|
||||
if (!this._openDialogs.length) {
|
||||
document.addEventListener('keydown', this._boundKeydown);
|
||||
}
|
||||
|
||||
@@ -199,10 +199,9 @@ export class MdDialog {
|
||||
*/
|
||||
private _handleKeydown(event: KeyboardEvent): void {
|
||||
let topDialog = this._openDialogs[this._openDialogs.length - 1];
|
||||
let canClose = topDialog ? !topDialog._containerInstance.dialogConfig.disableClose : false;
|
||||
|
||||
if (event.keyCode === ESCAPE && topDialog &&
|
||||
!topDialog._containerInstance.dialogConfig.disableClose) {
|
||||
|
||||
if (event.keyCode === ESCAPE && canClose) {
|
||||
topDialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user