File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
ui/admin/app/components/composed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11import { Slot } from "@radix-ui/react-slot" ;
22import { TooltipContentProps } from "@radix-ui/react-tooltip" ;
3+ import { useEffect , useState } from "react" ;
4+ import { useRef } from "react" ;
35
46import { cn } from "~/lib/utils" ;
57
@@ -31,9 +33,21 @@ export function Truncate({
3133 tooltipContentProps ?: TooltipContentProps ;
3234} ) {
3335 const Comp = asChild ? Slot : "p" ;
36+ const contentRef = useRef < HTMLDivElement > ( null ) ;
37+ const [ isContentTruncated , setIsContentTruncated ] = useState ( false ) ;
38+
39+ useEffect ( ( ) => {
40+ const element = contentRef . current ;
41+ if ( ! element ) return ;
42+
43+ // Check if content is actually truncated
44+ const isTruncated = element . scrollHeight > element . clientHeight ;
45+ setIsContentTruncated ( isTruncated ) ;
46+ } , [ children ] ) ;
3447
3548 const content = (
3649 < Comp
50+ ref = { contentRef }
3751 className = { cn (
3852 {
3953 "line-clamp-1" : clamp && clampLength === 1 ,
@@ -47,7 +61,7 @@ export function Truncate({
4761 </ Comp >
4862 ) ;
4963
50- if ( disableTooltip ) {
64+ if ( disableTooltip || ! isContentTruncated ) {
5165 return content ;
5266 }
5367
@@ -62,7 +76,7 @@ export function Truncate({
6276 </ TooltipContent >
6377
6478 < TooltipTrigger asChild >
65- < div className = { cn ( "cursor-pointer " , className ) } > { content } </ div >
79+ < div className = { cn ( "cursor-help " , className ) } > { content } </ div >
6680 </ TooltipTrigger >
6781 </ Tooltip >
6882 ) ;
You can’t perform that action at this time.
0 commit comments