function OverflownText({ children, ...props }) {
const ref = useRef(null);
const [isOverflown, setIsOverflown] = useState(false)
useEffect(() => {
const element = ref.current!;
setIsOverflown(element.scrollWidth > element.clientWidth);
}, []);
return (
<Tooltip label={children} isDisabled={!isOverflown}>
<Box position="relative" isTruncated ref={ref} {...props}>
{children}
</Box>
</Tooltip>
);
}
);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter