Skip to content

Commit a4f59bb

Browse files
authored
fix(TooltipProvider): return type * 2 (#803)
1 parent eca3776 commit a4f59bb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

.changeset/hip-doors-crash.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 the return type of the TooltipProvider the second time :)

src/components/overlays/Tooltip/TooltipProvider.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ReactElement, ReactNode, RefObject, useEffect, useState } from 'react';
1+
import {
2+
isValidElement,
3+
ReactElement,
4+
ReactNode,
5+
RefObject,
6+
useEffect,
7+
useState,
8+
} from 'react';
29

310
import { Styles } from '../../../tasty';
411

@@ -11,7 +18,7 @@ import {
1118

1219
export interface CubeTooltipProviderProps
1320
extends Omit<CubeTooltipTriggerProps, 'children'> {
14-
children: ReactElement | TooltipTriggerFunction;
21+
children: ReactNode | TooltipTriggerFunction;
1522
title?: ReactNode;
1623
tooltipStyles?: Styles;
1724
width?: CubeTooltipProps['width'];
@@ -29,20 +36,26 @@ export function TooltipProvider(props: CubeTooltipProviderProps): ReactElement {
2936

3037
// SSR: render without tooltip
3138
if (!rendered) {
32-
return isFunction ? (
39+
return (
3340
<>
34-
{children({}, { current: null } as unknown as RefObject<HTMLElement>)}
41+
{isFunction
42+
? children({}, { current: null } as unknown as RefObject<HTMLElement>)
43+
: children}
3544
</>
36-
) : (
37-
<>{children}</>
38-
);
45+
) as ReactElement;
3946
}
4047

4148
// Both patterns pass through to TooltipTrigger
4249
// The difference is whether we pass function or element as first child
4350
return (
4451
<TooltipTrigger {...otherProps}>
45-
{children}
52+
{isFunction ||
53+
isValidElement(children) ||
54+
typeof children === 'string' ? (
55+
children
56+
) : (
57+
<>{children}</>
58+
)}
4659
<Tooltip styles={tooltipStyles} {...(width ? { width } : null)}>
4760
{title}
4861
</Tooltip>

0 commit comments

Comments
 (0)