luo3house
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
2 deletions
-
components/modal/__tests__/hook.test.tsx
-
components/modal/useModal/HookModal.tsx
|
|
@ -350,4 +350,21 @@ describe('Modal.hook', () => { |
|
|
|
|
|
|
|
expect(document.body.querySelector('.bamboo')?.textContent).toEqual('好的'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('it should call forwarded afterClose', () => { |
|
|
|
const afterClose = jest.fn(); |
|
|
|
const Demo = () => { |
|
|
|
const [modal, contextHolder] = Modal.useModal(); |
|
|
|
React.useEffect(() => { |
|
|
|
modal.confirm({ title: 'Confirm', afterClose }); |
|
|
|
}, []); |
|
|
|
return contextHolder; |
|
|
|
}; |
|
|
|
|
|
|
|
render(<Demo />); |
|
|
|
const btns = document.body.querySelectorAll('.ant-btn'); |
|
|
|
fireEvent.click(btns[btns.length - 1]); |
|
|
|
|
|
|
|
expect(afterClose).toHaveBeenCalledTimes(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -16,7 +16,7 @@ export interface HookModalRef { |
|
|
|
} |
|
|
|
|
|
|
|
const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> = ( |
|
|
|
{ afterClose, config }, |
|
|
|
{ afterClose: hookAfterClose, config }, |
|
|
|
ref, |
|
|
|
) => { |
|
|
|
const [open, setOpen] = React.useState(true); |
|
|
@ -26,6 +26,11 @@ const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> = |
|
|
|
const prefixCls = getPrefixCls('modal'); |
|
|
|
const rootPrefixCls = getPrefixCls(); |
|
|
|
|
|
|
|
const afterClose = () => { |
|
|
|
hookAfterClose(); |
|
|
|
innerConfig.afterClose?.(); |
|
|
|
}; |
|
|
|
|
|
|
|
const close = (...args: any[]) => { |
|
|
|
setOpen(false); |
|
|
|
const triggerCancel = args.some((param) => param && param.triggerCancel); |
|
|
@ -59,7 +64,7 @@ const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> = |
|
|
|
okText={ |
|
|
|
innerConfig.okText || (mergedOkCancel ? contextLocale?.okText : contextLocale?.justOkText) |
|
|
|
} |
|
|
|
direction={direction} |
|
|
|
direction={innerConfig.direction || direction} |
|
|
|
cancelText={innerConfig.cancelText || contextLocale?.cancelText} |
|
|
|
/> |
|
|
|
); |
|
|
|