Skip to content

Commit

Permalink
fix(module:modal): nzMaskClosable not working in the confirm mode (#…
Browse files Browse the repository at this point in the history
…4347)

close #4344
  • Loading branch information
hsuanxyz authored Nov 7, 2019
1 parent 29f732b commit 475bbc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/modal/nz-modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ 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
}

options.nzModalType = 'confirm';
options.nzClassName = `ant-modal-confirm ant-modal-confirm-${confirmType} ${options.nzClassName || ''}`;
options.nzMaskClosable = false;
return this.create(options);
}

Expand Down
22 changes: 22 additions & 0 deletions components/modal/nz-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -919,6 +931,7 @@ export class TestVaryServiceCustomComponent {
template: ``
})
export class TestConfirmModalComponent {
maskClosedSpy = jasmine.createSpy();
constructor(public modalService: NzModalService) {}

createConfirm(): NzModalRef {
Expand All @@ -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();
Expand Down

0 comments on commit 475bbc4

Please sign in to comment.