mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
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
This commit is contained in:
parent
9db0fc7440
commit
2e011a379d
@ -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…
Reference in New Issue
Block a user