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 1
1
import { Slot } from "@radix-ui/react-slot" ;
2
2
import { TooltipContentProps } from "@radix-ui/react-tooltip" ;
3
+ import { useEffect , useState } from "react" ;
4
+ import { useRef } from "react" ;
3
5
4
6
import { cn } from "~/lib/utils" ;
5
7
@@ -31,9 +33,21 @@ export function Truncate({
31
33
tooltipContentProps ?: TooltipContentProps ;
32
34
} ) {
33
35
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 ] ) ;
34
47
35
48
const content = (
36
49
< Comp
50
+ ref = { contentRef }
37
51
className = { cn (
38
52
{
39
53
"line-clamp-1" : clamp && clampLength === 1 ,
@@ -47,7 +61,7 @@ export function Truncate({
47
61
</ Comp >
48
62
) ;
49
63
50
- if ( disableTooltip ) {
64
+ if ( disableTooltip || ! isContentTruncated ) {
51
65
return content ;
52
66
}
53
67
@@ -62,7 +76,7 @@ export function Truncate({
62
76
</ TooltipContent >
63
77
64
78
< TooltipTrigger asChild >
65
- < div className = { cn ( "cursor-pointer " , className ) } > { content } </ div >
79
+ < div className = { cn ( "cursor-help " , className ) } > { content } </ div >
66
80
</ TooltipTrigger >
67
81
</ Tooltip >
68
82
) ;
You can’t perform that action at this time.
0 commit comments