diff --git a/components/popover/__tests__/index.test.tsx b/components/popover/__tests__/index.test.tsx index d20b2def1d..ba40ee4409 100644 --- a/components/popover/__tests__/index.test.tsx +++ b/components/popover/__tests__/index.test.tsx @@ -49,8 +49,8 @@ describe('Popover', () => { ); fireEvent.click(container.querySelector('span')!); - expect(container.querySelector('.ant-popover-title')?.textContent).toBeFalsy(); - expect(container.querySelector('.ant-popover-inner-content')?.textContent).toBeFalsy(); + const popup = document.querySelector('.ant-popover'); + expect(popup).toBe(null); }); it('should not render popover when the title & content props is empty', () => { @@ -61,8 +61,8 @@ describe('Popover', () => { ); fireEvent.click(container.querySelector('span')!); - expect(container.querySelector('.ant-popover-title')?.textContent).toBeFalsy(); - expect(container.querySelector('.ant-popover-inner-content')?.textContent).toBeFalsy(); + const popup = document.querySelector('.ant-popover'); + expect(popup).toBe(null); }); it('props#overlay do not warn anymore', () => { diff --git a/components/popover/index.tsx b/components/popover/index.tsx index 225c344d92..23db59123e 100644 --- a/components/popover/index.tsx +++ b/components/popover/index.tsx @@ -1,11 +1,11 @@ import classNames from 'classnames'; import * as React from 'react'; -import { ConfigContext } from '../config-provider'; -import type { AbstractTooltipProps } from '../tooltip'; -import Tooltip from '../tooltip'; import type { RenderFunction } from '../_util/getRenderPropValue'; import { getRenderPropValue } from '../_util/getRenderPropValue'; import { getTransitionName } from '../_util/motion'; +import { ConfigContext } from '../config-provider'; +import type { AbstractTooltipProps } from '../tooltip'; +import Tooltip from '../tooltip'; import PurePanel from './PurePanel'; // CSSINJS import useStyle from './style'; @@ -21,17 +21,12 @@ interface OverlayProps { content?: PopoverProps['content']; } -const Overlay: React.FC = ({ title, content, prefixCls }) => { - if (!title && !content) { - return null; - } - return ( - <> - {title &&
{getRenderPropValue(title)}
} -
{getRenderPropValue(content)}
- - ); -}; +const Overlay: React.FC = ({ title, content, prefixCls }) => ( + <> + {title &&
{getRenderPropValue(title)}
} +
{getRenderPropValue(content)}
+ +); const Popover = React.forwardRef((props, ref) => { const { @@ -65,7 +60,9 @@ const Popover = React.forwardRef((props, ref) => { prefixCls={prefixCls} overlayClassName={overlayCls} ref={ref} - overlay={} + overlay={ + title || content ? : null + } transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)} data-popover-inject />,