Skip to content

Commit 79fd04b

Browse files
fix: render tooltips in portals
1 parent eabb7d4 commit 79fd04b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/components/Analysis/MoveTooltip.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import { createPortal } from 'react-dom'
23
import { ColorSanMapping } from 'src/types'
34

45
interface MoveTooltipProps {
@@ -22,14 +23,14 @@ export const MoveTooltip: React.FC<MoveTooltipProps> = ({
2223
position,
2324
isVisible = true,
2425
}) => {
25-
if (!isVisible || !position) return null
26+
if (!isVisible || !position || typeof window === 'undefined') return null
2627

2728
const san = colorSanMapping[move]?.san ?? move
2829
const color = colorSanMapping[move]?.color ?? '#fff'
2930

30-
return (
31+
const tooltipContent = (
3132
<div
32-
className="pointer-events-none fixed z-50 flex w-auto min-w-[12rem] flex-col overflow-hidden rounded-lg border border-white/30 bg-background-1 backdrop-blur-sm"
33+
className="pointer-events-none fixed z-50 flex w-auto min-w-[12rem] flex-col overflow-hidden rounded-lg border border-white/30 bg-background-1 text-primary backdrop-blur-sm"
3334
style={{
3435
left: position.x + 15,
3536
top: position.y - 10,
@@ -83,4 +84,6 @@ export const MoveTooltip: React.FC<MoveTooltipProps> = ({
8384
</div>
8485
</div>
8586
)
87+
88+
return createPortal(tooltipContent, document.body)
8689
}

0 commit comments

Comments
 (0)