diff --git a/web/containers/TagInput/index.tsx b/web/containers/TagInput/index.tsx index d45fafee5..160cd19e3 100644 --- a/web/containers/TagInput/index.tsx +++ b/web/containers/TagInput/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { Badge, Input, Tooltip } from '@janhq/joi' @@ -14,6 +14,75 @@ type Props = { onValueChanged?: (e: string | number | boolean | string[]) => void } +function TooltipBadge({ + item, + value, + onValueChanged, +}: { + item: string + value: string[] + onValueChanged?: (e: string[]) => void +}) { + const textRef = useRef(null) + const [isEllipsized, setIsEllipsized] = useState(false) + + useEffect(() => { + if (textRef.current) { + setIsEllipsized(textRef.current.scrollWidth > textRef.current.clientWidth) + } + }, [item]) + + return ( +
+ {isEllipsized ? ( + + + + {item} + + + +
+ } + content={item} + /> + ) : ( + + + {item} + + + + )} + + ) +} + const TagInput = ({ title, disabled = false, @@ -60,22 +129,17 @@ const TagInput = ({ }} /> {value.length > 0 && ( -
- {value.map((item, idx) => ( - - {item} - - - ))} +
+ {value.map((item, idx) => { + return ( + + ) + })}
)}