Skip to content

Commit a085f1b

Browse files
committed
fix: use portals in tooltip
1 parent fb1e976 commit a085f1b

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

src/components/Tooltip.tsx

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
arrow,
55
autoUpdate,
66
flip,
7+
FloatingPortal,
78
offset,
89
shift,
910
useFloating,
@@ -121,46 +122,49 @@ export const Tooltip: React.FC<TooltipProps> = (props) => {
121122
>
122123
{children}
123124
</TooltipWrapper>
124-
<ThemeProvider theme={theme || solvedThemes.dark}>
125-
<AnimatePresence>
126-
{isOpen && (
127-
<React.Fragment>
128-
<RenderComponent
129-
{...getFloatingProps({
130-
ref: floating,
131-
style: {
132-
position: strategy,
133-
top: y || 0,
134-
left: x || 0,
135-
},
136-
})}
137-
{...cardProps}
138-
transition={{ duration: 0.2, ease: 'easeInOut' }}
139-
initial={{ opacity: 0, y: 0, scale: 0.9 }}
140-
animate={{ opacity: 1, y: 8, scale: 1 }}
141-
exit={{ opacity: 0, y: 0, scale: 0.9 }}
142-
>
143-
{title}
144-
<Arrow
145-
ref={arrowRef}
146-
style={
147-
arrowPosition === 'bottom'
148-
? {
149-
left: arrowX ?? undefined,
150-
[arrowPosition]: -16,
151-
transform: `scaleY(-1)`,
152-
}
153-
: {
154-
top: arrowY !== null ? (arrowY || 0) - 16 : undefined,
155-
left: arrowX ?? undefined,
156-
}
157-
}
158-
/>
159-
</RenderComponent>
160-
</React.Fragment>
161-
)}
162-
</AnimatePresence>
163-
</ThemeProvider>
125+
<FloatingPortal>
126+
<ThemeProvider theme={theme || solvedThemes.dark}>
127+
<AnimatePresence>
128+
{isOpen && (
129+
<React.Fragment>
130+
<RenderComponent
131+
{...getFloatingProps({
132+
ref: floating,
133+
style: {
134+
position: strategy,
135+
top: y || 0,
136+
left: x || 0,
137+
},
138+
})}
139+
{...cardProps}
140+
transition={{ duration: 0.2, ease: 'easeInOut' }}
141+
initial={{ opacity: 0, y: 0, scale: 0.9 }}
142+
animate={{ opacity: 1, y: 8, scale: 1 }}
143+
exit={{ opacity: 0, y: 0, scale: 0.9 }}
144+
>
145+
{title}
146+
<Arrow
147+
ref={arrowRef}
148+
style={
149+
arrowPosition === 'bottom'
150+
? {
151+
left: arrowX ?? undefined,
152+
[arrowPosition]: -16,
153+
transform: `scaleY(-1)`,
154+
}
155+
: {
156+
top:
157+
arrowY !== null ? (arrowY || 0) - 16 : undefined,
158+
left: arrowX ?? undefined,
159+
}
160+
}
161+
/>
162+
</RenderComponent>
163+
</React.Fragment>
164+
)}
165+
</AnimatePresence>
166+
</ThemeProvider>
167+
</FloatingPortal>
164168
</React.Fragment>
165169
)
166170
}

0 commit comments

Comments
 (0)