diff --git a/components/_util/ActionButton.tsx b/components/_util/ActionButton.tsx index b0dd28c11f..db0ba99774 100644 --- a/components/_util/ActionButton.tsx +++ b/components/_util/ActionButton.tsx @@ -111,7 +111,7 @@ const ActionButton: React.FC = (props) => { clickedRef.current = false; } else { returnValueOfOnOk = actionFn(); - if (!returnValueOfOnOk) { + if (!isThenable(returnValueOfOnOk)) { onInternalClose(); return; } diff --git a/components/modal/__tests__/confirm.test.tsx b/components/modal/__tests__/confirm.test.tsx index 569af3340f..6b1d347fba 100644 --- a/components/modal/__tests__/confirm.test.tsx +++ b/components/modal/__tests__/confirm.test.tsx @@ -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(); + }); });