fix modal.confirm unable to close normally when onCancel and onOk return true (#49054)

* fix: fix modal.confirm unable to close normally when onCancel and onOk return true

* test: update test case
pull/49070/head^2
Wanpan 8 months ago committed by GitHub
parent 9db0fc7440
commit 2e011a379d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -111,7 +111,7 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
clickedRef.current = false;
} else {
returnValueOfOnOk = actionFn();
if (!returnValueOfOnOk) {
if (!isThenable(returnValueOfOnOk)) {
onInternalClose();
return;
}

@ -949,4 +949,24 @@ describe('Modal.confirm triggers callbacks correctly', () => {
expect(document.querySelector('.ant-btn-primary')?.textContent).toBe('test');
ConfigProvider.config({ holderRender: undefined });
});
it('onCancel and onOk return any results and should be closed', async () => {
Modal.confirm({ onOk: () => true });
await waitFakeTimer();
$$('.ant-btn-primary')[0].click();
await waitFakeTimer();
expect(document.querySelector('.ant-modal-root')).toBeFalsy();
Modal.confirm({ onOk: () => false });
await waitFakeTimer();
$$('.ant-btn-primary')[0].click();
await waitFakeTimer();
expect(document.querySelector('.ant-modal-root')).toBeFalsy();
Modal.confirm({ onCancel: () => undefined });
await waitFakeTimer();
$$('.ant-btn')[0].click();
await waitFakeTimer();
expect(document.querySelector('.ant-modal-root')).toBeFalsy();
});
});

Loading…
Cancel
Save