mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
fix: fix Alert findDOMNode error (#48868)
* fix: fix Alert findDOMNode error * fix: update test
This commit is contained in:
parent
c9f7f5d8e6
commit
eb218e80c6
@ -7,6 +7,7 @@ import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
|||||||
import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
|
import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import CSSMotion from 'rc-motion';
|
import CSSMotion from 'rc-motion';
|
||||||
|
import { composeRef } from 'rc-util/es/ref';
|
||||||
import pickAttrs from 'rc-util/lib/pickAttrs';
|
import pickAttrs from 'rc-util/lib/pickAttrs';
|
||||||
|
|
||||||
import type { ClosableType } from '../_util/hooks/useClosable';
|
import type { ClosableType } from '../_util/hooks/useClosable';
|
||||||
@ -234,10 +235,10 @@ const Alert = React.forwardRef<AlertRef, AlertProps>((props, ref) => {
|
|||||||
onLeaveStart={(node) => ({ maxHeight: node.offsetHeight })}
|
onLeaveStart={(node) => ({ maxHeight: node.offsetHeight })}
|
||||||
onLeaveEnd={afterClose}
|
onLeaveEnd={afterClose}
|
||||||
>
|
>
|
||||||
{({ className: motionClassName, style: motionStyle }) => (
|
{({ className: motionClassName, style: motionStyle }, setRef) => (
|
||||||
<div
|
<div
|
||||||
id={id}
|
id={id}
|
||||||
ref={internalRef}
|
ref={composeRef(internalRef, setRef)}
|
||||||
data-show={!closed}
|
data-show={!closed}
|
||||||
className={classNames(alertCls, motionClassName)}
|
className={classNames(alertCls, motionClassName)}
|
||||||
style={{ ...alert?.style, ...style, ...motionStyle }}
|
style={{ ...alert?.style, ...style, ...motionStyle }}
|
||||||
|
@ -26,6 +26,7 @@ describe('Alert', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show close button and could be closed', async () => {
|
it('should show close button and could be closed', async () => {
|
||||||
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
const onClose = jest.fn();
|
const onClose = jest.fn();
|
||||||
render(
|
render(
|
||||||
<Alert
|
<Alert
|
||||||
@ -36,13 +37,14 @@ describe('Alert', () => {
|
|||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole('button', { name: /close/i }));
|
await act(async () => {
|
||||||
|
await userEvent.click(screen.getByRole('button', { name: /close/i }));
|
||||||
act(() => {
|
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(onClose).toHaveBeenCalledTimes(1);
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
|
expect(errSpy).not.toHaveBeenCalled();
|
||||||
|
errSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('custom action', () => {
|
it('custom action', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user