fix(experimental/dialog): disableClose option not working (#13584)

* Fixes the `disableClose` option not working for `cdk-experimental/dialog`.
* Updates our unit tests that were supposed to catch the issue, but didn't. Also updates similar tests for `material/dialog` and `material/bottom-sheet`.

Fixes #13583.
This commit is contained in:
Kristiyan Kostadinov
2018-10-15 19:34:35 +03:00
committed by Andrew Seguin
parent ba7d53d5bb
commit 5d538d706c
4 changed files with 26 additions and 13 deletions
+8 -4
View File
@@ -696,7 +696,7 @@ describe('Dialog', () => {
});
describe('disableClose option', () => {
it('should prevent closing via clicks on the backdrop', () => {
it('should prevent closing via clicks on the backdrop', fakeAsync(() => {
dialog.openFromComponent(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -706,11 +706,13 @@ describe('Dialog', () => {
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
backdrop.click();
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('cdk-dialog-container')).toBeTruthy();
});
}));
it('should prevent closing via the escape key', () => {
it('should prevent closing via the escape key', fakeAsync(() => {
dialog.openFromComponent(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -718,9 +720,11 @@ describe('Dialog', () => {
viewContainerFixture.detectChanges();
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('cdk-dialog-container')).toBeTruthy();
});
}));
it('should allow for the disableClose option to be updated while open', fakeAsync(() => {
let dialogRef = dialog.openFromComponent(PizzaMsg, {
+2 -1
View File
@@ -225,11 +225,12 @@ export class Dialog implements OnDestroy {
// Create a reference to the dialog we're creating in order to give the user a handle
// to modify and close it.
const dialogRef = new this.dialogRefConstructor(overlayRef, dialogContainer, config.id);
const injector = this._createInjector<T>(config, dialogRef, dialogContainer);
const contentRef = dialogContainer.attachComponentPortal(
new ComponentPortal(componentOrTemplateRef, undefined, injector));
dialogRef.componentInstance = contentRef.instance;
dialogRef.disableClose = config.disableClose;
dialogRef.updateSize({width: config.width, height: config.height})
.updatePosition(config.position);
+8 -4
View File
@@ -429,7 +429,7 @@ describe('MatBottomSheet', () => {
});
describe('disableClose option', () => {
it('should prevent closing via clicks on the backdrop', () => {
it('should prevent closing via clicks on the backdrop', fakeAsync(() => {
bottomSheet.open(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -439,11 +439,13 @@ describe('MatBottomSheet', () => {
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
backdrop.click();
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('mat-bottom-sheet-container')).toBeTruthy();
});
}));
it('should prevent closing via the escape key', () => {
it('should prevent closing via the escape key', fakeAsync(() => {
bottomSheet.open(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -451,9 +453,11 @@ describe('MatBottomSheet', () => {
viewContainerFixture.detectChanges();
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('mat-bottom-sheet-container')).toBeTruthy();
});
}));
});
+8 -4
View File
@@ -814,7 +814,7 @@ describe('MatDialog', () => {
}));
describe('disableClose option', () => {
it('should prevent closing via clicks on the backdrop', () => {
it('should prevent closing via clicks on the backdrop', fakeAsync(() => {
dialog.open(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -824,11 +824,13 @@ describe('MatDialog', () => {
let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
backdrop.click();
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('mat-dialog-container')).toBeTruthy();
});
}));
it('should prevent closing via the escape key', () => {
it('should prevent closing via the escape key', fakeAsync(() => {
dialog.open(PizzaMsg, {
disableClose: true,
viewContainerRef: testViewContainerRef
@@ -836,9 +838,11 @@ describe('MatDialog', () => {
viewContainerFixture.detectChanges();
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
viewContainerFixture.detectChanges();
flush();
expect(overlayContainerElement.querySelector('mat-dialog-container')).toBeTruthy();
});
}));
it('should allow for the disableClose option to be updated while open', fakeAsync(() => {
let dialogRef = dialog.open(PizzaMsg, {