Skip to content

Commit d169452

Browse files
authored
fix(module:modal): no longer trigger any action when closing (#7336)
1 parent b5f82b5 commit d169452

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

components/modal/modal-ref.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
167167
}
168168

169169
private async trigger(action: NzTriggerAction): Promise<void> {
170+
if (this.state === NzModalState.CLOSING) {
171+
return;
172+
}
170173
const trigger = { ok: this.config.nzOnOk, cancel: this.config.nzOnCancel }[action];
171174
const loadingKey = { ok: 'nzOkLoading', cancel: 'nzCancelLoading' }[action] as 'nzOkLoading' | 'nzCancelLoading';
172175
const loading = this.config[loadingKey];

components/modal/modal.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,32 @@ describe('NzModal', () => {
908908
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0);
909909
}));
910910

911+
it('should omit any action when closing', async function () {
912+
const onOk = jasmine.createSpy('onOk', () => {});
913+
const onCancel = jasmine.createSpy('onCancel', () => {});
914+
const modalRef = modalService.create({
915+
nzContent: TestWithModalContentComponent,
916+
nzOnOk: onOk,
917+
nzOnCancel: onCancel
918+
});
919+
fixture.detectChanges();
920+
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(1);
921+
await modalRef.triggerOk();
922+
expect(onOk).toHaveBeenCalledTimes(1);
923+
fakeAsync(() => {
924+
expect(modalRef.getState()).toBe(NzModalState.CLOSING);
925+
modalRef.triggerOk();
926+
modalRef.triggerOk();
927+
modalRef.triggerCancel();
928+
modalRef.triggerCancel();
929+
expect(onOk).toHaveBeenCalledTimes(1);
930+
expect(onCancel).toHaveBeenCalledTimes(0);
931+
fixture.detectChanges();
932+
flush();
933+
expect(overlayContainerElement.querySelectorAll('nz-modal-container').length).toBe(0);
934+
});
935+
});
936+
911937
it('should set loading state when the callback is promise', fakeAsync(() => {
912938
const modalRef = modalService.create({
913939
nzContent: TestWithModalContentComponent,

0 commit comments

Comments
 (0)