Skip to content

Commit 39be6b6

Browse files
authored
fix(ItemBase): tooltip logic (#784)
1 parent 1f7cb17 commit 39be6b6

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.changeset/beige-readers-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix tooltip condition in ItemBase.

.changeset/khaki-kids-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Allow to rewrite the tooltip title in ItemBase.

src/components/content/ItemBase/ItemBase.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ import {
5353
Styles,
5454
tasty,
5555
} from '../../../tasty';
56-
import {
57-
mergeProps,
58-
useCombinedRefs,
59-
useLayoutEffect,
60-
} from '../../../utils/react';
56+
import { mergeProps, useCombinedRefs } from '../../../utils/react';
6157
import {
6258
CubeTooltipProviderProps,
6359
TooltipProvider,
@@ -491,10 +487,10 @@ const ItemBase = <T extends HTMLElement = HTMLDivElement>(
491487

492488
// Determine if auto tooltip is enabled
493489
const isAutoTooltipEnabled = useMemo(() => {
494-
if (tooltip === true) return true;
490+
if (tooltip === true && typeof children === 'string') return true;
495491
if (typeof tooltip === 'object' && tooltip?.auto) return true;
496492
return false;
497-
}, [tooltip]);
493+
}, [tooltip, typeof children]);
498494

499495
// Track label overflow for auto tooltip (only when enabled)
500496
const mergedLabelRef = useCombinedRefs((labelProps as any)?.ref);
@@ -519,7 +515,7 @@ const ItemBase = <T extends HTMLElement = HTMLDivElement>(
519515
}, [children, isAutoTooltipEnabled, checkLabelOverflow]);
520516

521517
useEffect(() => {
522-
if (!isAutoTooltipEnabled || typeof children !== 'string') return;
518+
if (!isAutoTooltipEnabled) return;
523519

524520
const label = mergedLabelRef.current;
525521
if (!label) return;
@@ -614,7 +610,7 @@ const ItemBase = <T extends HTMLElement = HTMLDivElement>(
614610
return (
615611
<TooltipProvider
616612
placement={defaultTooltipPlacement}
617-
title={children}
613+
title={tooltipProps.title ?? children}
618614
{...tooltipProps}
619615
>
620616
{itemElement}

0 commit comments

Comments
 (0)