I do not know about antdegin, But I faced this problem once and I was able to resolve it.
To know if an text tag has overflown this check will be truthy:
element.offsetWidth < element.scrollWidth.
I tried to think about a generic way to solve this issue and ended up with this component (this is not production ready!)
function SmartText({
TypographyComponent = "h1",
TypographyComponentProps = {},
TooltipComponent = ({ children }) => children, // just for demo purpose, it will do nothing basically if not passed
ToolTipComponentProps = {},
children = ""
}) {
const textComponentRef = React.useRef(null);
const [tooltipTitle, setTooltipTitle] = React.useState("");
React.useEffect(() => {
if (
textComponentRef.current &&
textComponentRef.current.offsetWidth <
textComponentRef.current.scrollWidth
) {
setTooltipTitle(textComponentRef.current.innerText);
}
}, [children]);
return (
<TooltipComponent {...ToolTipComponentProps} title={tooltipTitle}>
<TypographyComponent {...TypographyComponentProps} ref={textComponentRef}>
{children}
</TypographyComponent>
</TooltipComponent>
);
}
The TypographyComponent in your case is the Paragraph, to use this method, the TypographyComponent has to forward the ref or to support it.
I used the SmartText with @material-ui tooltip like this:
<SmartText
TypographyComponentProps={{
style: {
whiteSpace: "nowrap",
maxWidth: 500,
textOverflow: "ellipsis",
overflow: "hidden",
textAlign: "left"
}
}}
TooltipComponent={Tooltip}
ToolTipComponentProps={{
placement: "right"
}}
>
Tooltip is needed because this text is long
</SmartText>
<SmartText
TypographyComponentProps={{
style: {
whiteSpace: "nowrap",
maxWidth: 300,
textOverflow: "ellipsis",
overflow: "hidden",
textAlign: "left"
}
}}
TooltipComponent={Tooltip}
ToolTipComponentProps={{
placement: "right"
}}
>
No tooltip needed
</SmartText>
Finally, here is working codesandbox demo