Skip to content

Commit 4ce2b43

Browse files
authored
fix: tools description help cursor & conditional tooltip based on content length (#1806)
1 parent 6adc07f commit 4ce2b43

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ui/admin/app/components/composed/typography.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Slot } from "@radix-ui/react-slot";
22
import { TooltipContentProps } from "@radix-ui/react-tooltip";
3+
import { useEffect, useState } from "react";
4+
import { useRef } from "react";
35

46
import { 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
);

0 commit comments

Comments
 (0)