From d16945249a28338ba480af46ff037d69b67b4af4 Mon Sep 17 00:00:00 2001 From: maroon1 Date: Thu, 21 Apr 2022 10:32:15 +0800 Subject: [PATCH] fix(module:modal): no longer trigger any action when closing (#7336) --- components/modal/modal-ref.ts | 3 +++ components/modal/modal.spec.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/components/modal/modal-ref.ts b/components/modal/modal-ref.ts index fb0256080a..bbb2ed70ed 100644 --- a/components/modal/modal-ref.ts +++ b/components/modal/modal-ref.ts @@ -167,6 +167,9 @@ export class NzModalRef implements NzModalLegacyAP } private async trigger(action: NzTriggerAction): Promise { + if (this.state === NzModalState.CLOSING) { + return; + } const trigger = { ok: this.config.nzOnOk, cancel: this.config.nzOnCancel }[action]; const loadingKey = { ok: 'nzOkLoading', cancel: 'nzCancelLoading' }[action] as 'nzOkLoading' | 'nzCancelLoading'; const loading = this.config[loadingKey]; diff --git a/components/modal/modal.spec.ts b/components/modal/modal.spec.ts index 276a31b43e..fc92498fdf 100644 --- a/components/modal/modal.spec.ts +++ b/components/modal/modal.spec.ts @@ -908,6 +908,32 @@ describe('NzModal', () => { expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0); })); + it('should omit any action when closing', async function () { + const onOk = jasmine.createSpy('onOk', () => {}); + const onCancel = jasmine.createSpy('onCancel', () => {}); + const modalRef = modalService.create({ + nzContent: TestWithModalContentComponent, + nzOnOk: onOk, + nzOnCancel: onCancel + }); + fixture.detectChanges(); + expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(1); + await modalRef.triggerOk(); + expect(onOk).toHaveBeenCalledTimes(1); + fakeAsync(() => { + expect(modalRef.getState()).toBe(NzModalState.CLOSING); + modalRef.triggerOk(); + modalRef.triggerOk(); + modalRef.triggerCancel(); + modalRef.triggerCancel(); + expect(onOk).toHaveBeenCalledTimes(1); + expect(onCancel).toHaveBeenCalledTimes(0); + fixture.detectChanges(); + flush(); + expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0); + }); + }); + it('should set loading state when the callback is promise', fakeAsync(() => { const modalRef = modalService.create({ nzContent: TestWithModalContentComponent,