From 87f39244e10d9a67b1af386ddbf913a36007da78 Mon Sep 17 00:00:00 2001 From: Aaron674092290 Date: Thu, 8 Sep 2022 17:30:49 +0800 Subject: [PATCH] fix: unable to close modal when using visible in Modal.confirm().update (#37471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: unable to close modal when using visible in Modal.confirm().update * chore: test case update Co-authored-by: yangguangte Co-authored-by: 二货机器人 --- components/modal/__tests__/confirm.test.tsx | 27 +++++++++++++++++++++ components/modal/confirm.tsx | 10 +++++++- scripts/post-script.js | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/components/modal/__tests__/confirm.test.tsx b/components/modal/__tests__/confirm.test.tsx index 27eb575262..8103b380fe 100644 --- a/components/modal/__tests__/confirm.test.tsx +++ b/components/modal/__tests__/confirm.test.tsx @@ -850,4 +850,31 @@ describe('Modal.confirm triggers callbacks correctly', () => { jest.useRealTimers(); }); + + // https://github.com/ant-design/ant-design/issues/37461 + it('Update should closable', async () => { + jest.useFakeTimers(); + + Modal.confirm({}).update({ + visible: true, + }); + + await act(async () => { + jest.runAllTimers(); + await sleep(); + }); + + expect($$('.ant-modal-confirm-confirm')).toHaveLength(1); + + $$('.ant-modal-confirm-btns > .ant-btn')[0].click(); + + await act(async () => { + jest.runAllTimers(); + await sleep(); + }); + + expect($$('.ant-modal-confirm-confirm')).toHaveLength(0); + + jest.useRealTimers(); + }); }); diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index a8e05c9574..6845cc4f01 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -48,7 +48,14 @@ export default function confirm(config: ModalFuncProps) { reactUnmount(container); } - function render({ okText, cancelText, prefixCls: customizePrefixCls, ...props }: any) { + function render({ + okText, + cancelText, + prefixCls: customizePrefixCls, + open, + visible, + ...props + }: any) { /** * https://github.com/ant-design/ant-design/issues/23623 * @@ -65,6 +72,7 @@ export default function confirm(config: ModalFuncProps) { reactRender(