Skip to content

Commit b32690b

Browse files
committed
Fix
1 parent a071c7e commit b32690b

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

packages/design-system/src/components/tooltip.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,36 @@ import {
66
import { Button } from "./button";
77
import { Box } from "./box";
88
import { InputField } from "./input-field";
9+
import { useState } from "react";
910

1011
export default {
1112
title: "Library/Tooltip",
1213
};
1314

1415
export const TooltipDelay = () => {
16+
const [error, setError] = useState<string[]>([]);
1517
return (
1618
<TooltipProvider>
1719
<TooltipDesign content="HELLO" delayDuration={1000}>
1820
<Button>Hover me</Button>
1921
</TooltipDesign>
2022

21-
<InputErrorsTooltip errors={[]} side={"right"}>
23+
<InputErrorsTooltip errors={error} side={"right"}>
2224
<InputField
2325
id="input"
2426
placeholder="Input"
2527
css={{
2628
width: 200,
2729
}}
30+
onChange={(event) => {
31+
setError(event.target.value !== "" ? ["Error"] : []);
32+
}}
2833
/>
2934
</InputErrorsTooltip>
35+
36+
<TooltipDesign content={undefined} delayDuration={1000}>
37+
<Button>Hover me</Button>
38+
</TooltipDesign>
3039
</TooltipProvider>
3140
);
3241
};

packages/design-system/src/components/tooltip.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,24 @@ export const Tooltip = forwardRef(
102102
<TooltipPrimitive.Trigger asChild {...triggerProps}>
103103
{children}
104104
</TooltipPrimitive.Trigger>
105-
<TooltipPrimitive.Portal>
106-
<Content
107-
ref={ref}
108-
side="top"
109-
align="center"
110-
sideOffset={2}
111-
collisionPadding={8}
112-
arrowPadding={8}
113-
{...props}
114-
>
115-
{typeof content === "string" ? <Text>{content}</Text> : content}
116-
<Box css={{ color: theme.colors.transparentExtreme }}>
117-
<Arrow offset={5} width={11} height={5} />
118-
</Box>
119-
</Content>
120-
</TooltipPrimitive.Portal>
105+
{content != null && (
106+
<TooltipPrimitive.Portal>
107+
<Content
108+
ref={ref}
109+
side="top"
110+
align="center"
111+
sideOffset={2}
112+
collisionPadding={8}
113+
arrowPadding={8}
114+
{...props}
115+
>
116+
{typeof content === "string" ? <Text>{content}</Text> : content}
117+
<Box css={{ color: theme.colors.transparentExtreme }}>
118+
<Arrow offset={5} width={11} height={5} />
119+
</Box>
120+
</Content>
121+
</TooltipPrimitive.Portal>
122+
)}
121123
</TooltipPrimitive.Root>
122124
);
123125
}
@@ -202,12 +204,11 @@ export const InputErrorsTooltip = ({
202204
}
203205
}, []);
204206

205-
// We intentionally always pass non empty content to avoid optimization inside Tooltip
206-
// where it renders {children} directly if content is empty.
207-
// If this optimization accur, the input will remount which will cause focus loss
208-
// and current value loss.
207+
// Wrap the error tooltip with its own provider to avoid logic intersection with ordinary tooltips.
208+
// This is especially important for hover delays.
209+
// Here we ensure that hovering over the tooltip trigger after any input will not show the tooltip immediately.
209210
return (
210-
<>
211+
<TooltipProvider>
211212
<Box ref={ref as never} css={{ display: "contents" }}></Box>
212213
<Tooltip
213214
{...rest}
@@ -225,6 +226,6 @@ export const InputErrorsTooltip = ({
225226
>
226227
{children}
227228
</Tooltip>
228-
</>
229+
</TooltipProvider>
229230
);
230231
};

0 commit comments

Comments
 (0)