From b4da5cba4816cd28c2b70e7349c3ef8de171c59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Wed, 25 Mar 2020 16:50:43 +0800 Subject: [PATCH] :bug: Fix Alert cannot work with Tooltip (#22594) close #22579 --- components/alert/__tests__/index.test.js | 45 ++++++++++++++++++++++++ components/alert/index.tsx | 16 ++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/components/alert/__tests__/index.test.js b/components/alert/__tests__/index.test.js index c943db3f2f..d7680784ef 100644 --- a/components/alert/__tests__/index.test.js +++ b/components/alert/__tests__/index.test.js @@ -1,7 +1,10 @@ import React from 'react'; import { mount } from 'enzyme'; import Alert from '..'; +import Tooltip from '../../tooltip'; +import Popconfirm from '../../popconfirm'; import rtlTest from '../../../tests/shared/rtlTest'; +import { sleep } from '../../../tests/utils'; const { ErrorBoundary } = Alert; @@ -66,4 +69,46 @@ describe('Alert', () => { // eslint-disable-next-line jest/no-standalone-expect expect(wrapper.render()).toMatchSnapshot(); }); + + it('could be used with Tooltip', async () => { + jest.useRealTimers(); + const wrapper = mount( + + + , + ); + wrapper.find('.ant-alert').simulate('mouseenter'); + await sleep(0); + expect( + wrapper + .find(Tooltip) + .instance() + .getPopupDomNode(), + ).toBeTruthy(); + jest.useFakeTimers(); + }); + + it('could be used with Popconfirm', async () => { + jest.useRealTimers(); + const wrapper = mount( + + + , + ); + wrapper.find('.ant-alert').simulate('click'); + await sleep(0); + expect( + wrapper + .find(Popconfirm) + .instance() + .getPopupDomNode(), + ).toBeTruthy(); + jest.useFakeTimers(); + }); }); diff --git a/components/alert/index.tsx b/components/alert/index.tsx index 3584ffcce7..047e6a4fe7 100755 --- a/components/alert/index.tsx +++ b/components/alert/index.tsx @@ -42,6 +42,9 @@ export interface AlertProps { className?: string; banner?: boolean; icon?: React.ReactNode; + onMouseEnter?: React.MouseEventHandler; + onMouseLeave?: React.MouseEventHandler; + onClick?: React.MouseEventHandler; } export interface AlertState { @@ -103,6 +106,9 @@ export default class Alert extends React.Component { className = '', style, icon, + onMouseEnter, + onMouseLeave, + onClick, } = this.props; let { closable, type, showIcon } = this.props; const { closing, closed } = this.state; @@ -173,7 +179,15 @@ export default class Alert extends React.Component { transitionName={`${prefixCls}-slide-up`} onEnd={this.animationEnd} > -
+
{showIcon ? iconNode : null} {message} {description}