How can I show tooltip ONLY when ellipsis is activated? · Issue #4202 · chakra-ui/chakra-ui

PHOTO EMBED

Thu Jun 30 2022 13:49:30 GMT+0000 (Coordinated Universal Time)

Saved by @Wario

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>
    );
  }
);
content_copyCOPY

https://github.com/chakra-ui/chakra-ui/issues/4202