From 66066709c56db9911cd17eaf5614b232354e5445 Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Mon, 31 Mar 2025 15:42:31 +0200 Subject: [PATCH 1/3] fix: enhance Tooltip component for touch device support --- src/components/primitives/Tooltip.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/primitives/Tooltip.tsx b/src/components/primitives/Tooltip.tsx index f0bfc4e31..5dc5a3eb1 100644 --- a/src/components/primitives/Tooltip.tsx +++ b/src/components/primitives/Tooltip.tsx @@ -1,3 +1,4 @@ +import { useState, useEffect } from "react"; import * as RadixTooltip from "@radix-ui/react-tooltip"; import { useTheme } from "../../context/Theme.context"; import type { Component } from "../../utils/types"; @@ -12,12 +13,26 @@ export type TooltipProps = Component<{ export default function Tooltip({ helper, children, icon = true, className }: TooltipProps) { const { vars } = useTheme(); + const [open, setOpen] = useState(false); + const [isTouchDevice, setIsTouchDevice] = useState(false); + + useEffect(() => { + if (!("ontouchstart" in window)) return; + const checkTouch = () => setIsTouchDevice(true); + checkTouch(); + window.addEventListener("resize", checkTouch); + return () => window.removeEventListener("resize", checkTouch); + }, []); return ( - + - + {/* biome-ignore lint/a11y/useKeyWithClickEvents: */} + setOpen(prev => !prev) : undefined}>
{children}
{!!icon && }
From dc21aaa5c2a9a152e354282f7e122f192965ac18 Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Mon, 31 Mar 2025 15:50:30 +0200 Subject: [PATCH 2/3] fix: simplify touch device detection in Tooltip component --- src/components/primitives/Tooltip.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/primitives/Tooltip.tsx b/src/components/primitives/Tooltip.tsx index 5dc5a3eb1..a4d60a247 100644 --- a/src/components/primitives/Tooltip.tsx +++ b/src/components/primitives/Tooltip.tsx @@ -18,10 +18,7 @@ export default function Tooltip({ helper, children, icon = true, className }: To useEffect(() => { if (!("ontouchstart" in window)) return; - const checkTouch = () => setIsTouchDevice(true); - checkTouch(); - window.addEventListener("resize", checkTouch); - return () => window.removeEventListener("resize", checkTouch); + setIsTouchDevice(true); }, []); return ( From 833c915b1446151143310dd18576009654ec8acb Mon Sep 17 00:00:00 2001 From: Hugo Lextrait Date: Mon, 31 Mar 2025 16:08:38 +0200 Subject: [PATCH 3/3] fix: prevent error in Tooltip component on server-side rendering --- src/components/primitives/Tooltip.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/primitives/Tooltip.tsx b/src/components/primitives/Tooltip.tsx index 28c8f8090..640c5c2cd 100644 --- a/src/components/primitives/Tooltip.tsx +++ b/src/components/primitives/Tooltip.tsx @@ -18,6 +18,7 @@ export default function Tooltip({ helper, onOpen, children, icon = true, classNa const [isTouchDevice, setIsTouchDevice] = useState(false); useEffect(() => { + if (typeof document === "undefined") return; if (!("ontouchstart" in window)) return; setIsTouchDevice(true); }, []);