Skip to content

Commit

Permalink
fix(module:modal): fix multiple nzOnCancel calls (#1590)
Browse files Browse the repository at this point in the history
close #958
  • Loading branch information
dmytroyarmak authored and vthinkxie committed Jun 5, 2018
1 parent b8e4432 commit bc07be2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/modal/nz-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R> impleme
}

onClickMask($event: MouseEvent): void {
if (this.nzMask && this.nzMaskClosable && ($event.target as HTMLElement).classList.contains('ant-modal-wrap')) {
if (
this.nzMask &&
this.nzMaskClosable &&
($event.target as HTMLElement).classList.contains('ant-modal-wrap') &&
this.nzVisible
) {
this.onClickOkCancel('cancel');
}
}
Expand All @@ -227,7 +232,9 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R> impleme
}

private onClickCloseBtn(): void {
this.onClickOkCancel('cancel');
if (this.nzVisible) {
this.onClickOkCancel('cancel');
}
}

private onClickOkCancel(type: 'ok' | 'cancel'): void {
Expand Down
4 changes: 4 additions & 0 deletions components/modal/nz-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ describe('modal testing (legacy)', () => {
modalInstance.nzMaskClosable = true;
(modalElement.querySelector('.ant-modal-wrap') as HTMLElement).click();
expect(console.log).toHaveBeenCalledWith('click cancel');
// second click on mask should not trigger nzOnCancel
(console.log as jasmine.Spy).calls.reset();
(modalElement.querySelector('.ant-modal-wrap') as HTMLElement).click();
expect(console.log).not.toHaveBeenCalledWith('click cancel');
flush();
expectModalDestroyed(tempModalId, true); // should be destroyed
})); // /basic props
Expand Down

0 comments on commit bc07be2

Please sign in to comment.