Browse Source

🐛 Fix Tooltip title 0 is not shown (#20894)

close #20891
pull/20926/head
偏右 5 years ago
committed by GitHub
parent
commit
b112378de3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      components/tooltip/__tests__/tooltip.test.js
  2. 14
      components/tooltip/index.tsx

10
components/tooltip/__tests__/tooltip.test.js

@ -241,4 +241,14 @@ describe('Tooltip', () => {
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
// https://github.com/ant-design/ant-design/issues/20891
it('should display zero', async () => {
const wrapper = mount(
<Tooltip title={0} visible>
<div />
</Tooltip>,
);
expect(wrapper.find('.ant-tooltip-inner').getDOMNode().innerHTML).toBe('0');
});
});

14
components/tooltip/index.tsx

@ -226,7 +226,15 @@ class Tooltip extends React.Component<TooltipProps, any> {
isNoTitle() {
const { title, overlay } = this.props;
return !title && !overlay; // overlay for old version compatibility
return !title && !overlay && title !== 0; // overlay for old version compatibility
}
getOverlay() {
const { title, overlay } = this.props;
if (title === 0) {
return title;
}
return overlay || title || '';
}
renderTooltip = ({
@ -236,8 +244,6 @@ class Tooltip extends React.Component<TooltipProps, any> {
const { props, state } = this;
const {
prefixCls: customizePrefixCls,
title,
overlay,
openClassName,
getPopupContainer,
getTooltipContainer,
@ -266,7 +272,7 @@ class Tooltip extends React.Component<TooltipProps, any> {
getTooltipContainer={getPopupContainer || getTooltipContainer || getContextPopupContainer}
ref={this.saveTooltip}
builtinPlacements={this.getPlacements()}
overlay={overlay || title || ''}
overlay={this.getOverlay()}
visible={visible}
onVisibleChange={this.onVisibleChange}
onPopupAlign={this.onPopupAlign}

Loading…
Cancel
Save