From e3a7635a2a089223f6573c4726a1de0509bec525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Sat, 6 Jun 2020 15:25:47 +0800 Subject: [PATCH] fix: Statistic don't work with Tooltip (#24782) close #24774 --- components/statistic/Statistic.tsx | 15 +++++++-------- components/statistic/__tests__/index.test.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/components/statistic/Statistic.tsx b/components/statistic/Statistic.tsx index cf15d6ff5d..05627eeff9 100644 --- a/components/statistic/Statistic.tsx +++ b/components/statistic/Statistic.tsx @@ -21,6 +21,8 @@ export interface StatisticProps extends FormatConfig { title?: React.ReactNode; prefix?: React.ReactNode; suffix?: React.ReactNode; + onMouseEnter?: React.MouseEventHandler; + onMouseLeave?: React.MouseEventHandler; } const Statistic: React.FC = props => { @@ -35,22 +37,19 @@ const Statistic: React.FC = props => { prefix, suffix, direction, + onMouseEnter, + onMouseLeave, } = props; - - let valueNode: React.ReactNode = ; - - if (valueRender) { - valueNode = valueRender(valueNode); - } + const valueNode = ; const cls = classNames(prefixCls, className, { [`${prefixCls}-rtl`]: direction === 'rtl', }); return ( -
+
{title &&
{title}
}
{prefix && {prefix}} - {valueNode} + {valueRender ? valueRender(valueNode) : valueNode} {suffix && {suffix}}
diff --git a/components/statistic/__tests__/index.test.js b/components/statistic/__tests__/index.test.js index d251db4869..406786d626 100644 --- a/components/statistic/__tests__/index.test.js +++ b/components/statistic/__tests__/index.test.js @@ -82,6 +82,26 @@ describe('Statistic', () => { expect(onFinish).not.toHaveBeenCalled(); }); + it('responses hover events', () => { + const onMouseEnter = jest.fn(); + const onMouseLeave = jest.fn(); + const wrapper = mount(); + wrapper.simulate('mouseenter'); + expect(onMouseEnter).toHaveBeenCalled(); + wrapper.simulate('mouseleave'); + expect(onMouseLeave).toHaveBeenCalled(); + }); + + it('responses hover events for Countdown', () => { + const onMouseEnter = jest.fn(); + const onMouseLeave = jest.fn(); + const wrapper = mount(); + wrapper.simulate('mouseenter'); + expect(onMouseEnter).toHaveBeenCalled(); + wrapper.simulate('mouseleave'); + expect(onMouseLeave).toHaveBeenCalled(); + }); + describe('time finished', () => { it('not call if time already passed', () => { const now = Date.now() - 1000;