fix: Statistic don't work with Tooltip (#24782)

close #24774
pull/24785/head
偏右 5 years ago committed by GitHub
parent e508ee778d
commit e3a7635a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,8 @@ export interface StatisticProps extends FormatConfig {
title?: React.ReactNode;
prefix?: React.ReactNode;
suffix?: React.ReactNode;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
}
const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = props => {
@ -35,22 +37,19 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = props => {
prefix,
suffix,
direction,
onMouseEnter,
onMouseLeave,
} = props;
let valueNode: React.ReactNode = <StatisticNumber {...props} value={value} />;
if (valueRender) {
valueNode = valueRender(valueNode);
}
const valueNode = <StatisticNumber {...props} value={value} />;
const cls = classNames(prefixCls, className, {
[`${prefixCls}-rtl`]: direction === 'rtl',
});
return (
<div className={cls} style={style}>
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
{title && <div className={`${prefixCls}-title`}>{title}</div>}
<div style={valueStyle} className={`${prefixCls}-content`}>
{prefix && <span className={`${prefixCls}-content-prefix`}>{prefix}</span>}
{valueNode}
{valueRender ? valueRender(valueNode) : valueNode}
{suffix && <span className={`${prefixCls}-content-suffix`}>{suffix}</span>}
</div>
</div>

@ -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(<Statistic onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />);
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(<Statistic.Countdown onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />);
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;

Loading…
Cancel
Save