From 475bbc46069200bac91a8f8795b4306755915115 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Thu, 7 Nov 2019 16:43:27 +0800 Subject: [PATCH] fix(module:modal): `nzMaskClosable` not working in the confirm mode (#4347) close #4344 --- components/modal/nz-modal.service.ts | 4 +++- components/modal/nz-modal.spec.ts | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/components/modal/nz-modal.service.ts b/components/modal/nz-modal.service.ts index e7bb97edc7d..7a52c3737dd 100644 --- a/components/modal/nz-modal.service.ts +++ b/components/modal/nz-modal.service.ts @@ -100,6 +100,9 @@ export class NzModalService { if (!('nzWidth' in options)) { options.nzWidth = 416; } + if (!('nzMaskClosable' in options)) { + options.nzMaskClosable = false; + } if (typeof options.nzOnOk !== 'function') { // NOTE: only support function currently by calling confirm() options.nzOnOk = () => {}; // Leave a empty function to close this modal by default @@ -107,7 +110,6 @@ export class NzModalService { options.nzModalType = 'confirm'; options.nzClassName = `ant-modal-confirm ant-modal-confirm-${confirmType} ${options.nzClassName || ''}`; - options.nzMaskClosable = false; return this.create(options); } diff --git a/components/modal/nz-modal.spec.ts b/components/modal/nz-modal.spec.ts index 539ee9982f3..69781d46f59 100644 --- a/components/modal/nz-modal.spec.ts +++ b/components/modal/nz-modal.spec.ts @@ -288,6 +288,18 @@ describe('modal testing (legacy)', () => { instance = fixture.debugElement.componentInstance; }); + it('should click mask is closable', fakeAsync(() => { + const modalRef = instance.createMaskClosableConfirm(); + const modalElement = modalRef.getElement(); + fixture.detectChanges(); + expect(modalRef.getInstance().nzMaskClosable).toBe(true); + const maskElement = modalElement.querySelector('.ant-modal-wrap') as HTMLDivElement; + maskElement!.click(); + flush(); + fixture.detectChanges(); + expect(instance.maskClosedSpy).toHaveBeenCalled(); + })); + it('boundary detection for options', fakeAsync(() => { const spy = spyOn(console, 'warn'); @@ -919,6 +931,7 @@ export class TestVaryServiceCustomComponent { template: `` }) export class TestConfirmModalComponent { + maskClosedSpy = jasmine.createSpy(); constructor(public modalService: NzModalService) {} createConfirm(): NzModalRef { @@ -932,6 +945,15 @@ export class TestConfirmModalComponent { }); } + createMaskClosableConfirm(): NzModalRef { + return this.modalService.confirm({ + nzMaskClosable: true, + nzOnCancel: () => { + this.maskClosedSpy(); + } + }); + } + createOtherModals(): string[] { return ['info', 'success', 'error', 'warning'].map(type => { const modalId = generateUniqueId();