Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-doors-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cube-dev/ui-kit": patch
---

Fix the return type of the TooltipProvider the second time :)
29 changes: 21 additions & 8 deletions src/components/overlays/Tooltip/TooltipProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ReactElement, ReactNode, RefObject, useEffect, useState } from 'react';
import {
isValidElement,
ReactElement,
ReactNode,
RefObject,
useEffect,
useState,
} from 'react';

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

Expand All @@ -11,7 +18,7 @@ import {

export interface CubeTooltipProviderProps
extends Omit<CubeTooltipTriggerProps, 'children'> {
children: ReactElement | TooltipTriggerFunction;
children: ReactNode | TooltipTriggerFunction;
title?: ReactNode;
tooltipStyles?: Styles;
width?: CubeTooltipProps['width'];
Expand All @@ -29,20 +36,26 @@ export function TooltipProvider(props: CubeTooltipProviderProps): ReactElement {

// SSR: render without tooltip
if (!rendered) {
return isFunction ? (
return (
<>
{children({}, { current: null } as unknown as RefObject<HTMLElement>)}
{isFunction
? children({}, { current: null } as unknown as RefObject<HTMLElement>)
: children}
</>
) : (
<>{children}</>
);
) as ReactElement;
}

// Both patterns pass through to TooltipTrigger
// The difference is whether we pass function or element as first child
return (
<TooltipTrigger {...otherProps}>
{children}
{isFunction ||
isValidElement(children) ||
typeof children === 'string' ? (
children
) : (
<>{children}</>
)}
<Tooltip styles={tooltipStyles} {...(width ? { width } : null)}>
{title}
</Tooltip>
Expand Down
Loading