From 2e011a379dff86bfe05a9ff1465dfb5d574ff415 Mon Sep 17 00:00:00 2001 From: Wanpan Date: Fri, 24 May 2024 13:53:57 +0800 Subject: [PATCH] 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 --- components/_util/ActionButton.tsx | 2 +- components/modal/__tests__/confirm.test.tsx | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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(); + }); });