import { Tooltip } from 'antd'; import type { TooltipProps } from 'antd/lib/tooltip'; import React from 'react'; type BeyondHidingProps = Omit & { className?: string; style?: React.CSSProperties; title: React.ReactNode; }; const BeyondHiding = ({ className, style, title, ...props }: BeyondHidingProps) => { const [isShow, setIsShow] = useState(false); const contentRef = useRef(null); const isShowTooltip = (): void => { // 计算span标签的offsetWidth与盒子元素的offsetWidth,给isShow赋值 if (contentRef.current && contentRef.current.parentElement) { const spanWidth = contentRef.current.offsetWidth; const parentWidth = contentRef.current.parentElement.offsetWidth; if (spanWidth > parentWidth) { setIsShow(true); } } }; return ( setIsShow(false)} onMouseOver={isShowTooltip} > {title} ); }; export default BeyondHiding;