fix: unable to close modal when using visible in Modal.confirm().update (#37471)

* fix: unable to close modal when using visible in Modal.confirm().update

* chore: test case update

Co-authored-by: yangguangte <yangguangte@bytedance.com>
Co-authored-by: 二货机器人 <smith3816@gmail.com>
This commit is contained in:
Aaron674092290 2022-09-08 17:30:49 +08:00 committed by GitHub
parent 7c087deded
commit 87f39244e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View File

@ -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();
});
});

View File

@ -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(
<ConfirmDialog
{...props}
open={open ?? visible}
prefixCls={prefixCls}
rootPrefixCls={rootPrefixCls}
iconPrefixCls={iconPrefixCls}

View File

@ -13,6 +13,7 @@ const DEPRECIATED_VERSION = {
'https://github.com/ant-design/ant-design/pull/36800',
'https://github.com/ant-design/ant-design/issues/37024',
],
'4.23.0': ['https://github.com/ant-design/ant-design/issues/37461'],
};
function matchDeprecated(version) {