Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

scope CSS selectors, add pointer-events-none, instant focus, unmount cleanup, made prettier

Phillip Lagoc5732b1501fc1
diff --git a/web/app/globals.css b/web/app/globals.css
index 0decc4533..744d3d33d 100644
--- a/web/app/globals.css
+++ b/web/app/globals.css
@@ -574,7 +574,7 @@
}
.tooltip-content {
- @apply absolute z-50 rounded-lg bg-[var(--popover)] px-3 py-1.5 text-xs shadow-md text-[var(--popover-foreground)];
+ @apply absolute z-50 rounded-lg bg-[var(--popover)] px-3 py-1.5 text-xs shadow-md text-[var(--popover-foreground)] pointer-events-none;
animation: tooltip-fade-in 150ms ease-out;
}
@@ -586,11 +586,11 @@
@apply mt-0.5 text-[11px] text-[var(--muted-foreground)] truncate;
}
-[data-side="right"] {
+.tooltip-content[data-side="right"] {
@apply left-full top-1/2 -translate-y-1/2 ml-2 max-w-[200px];
}
-[data-side="bottom"] {
+.tooltip-content[data-side="bottom"] {
@apply bottom-[-40px] left-1/2 -translate-x-1/2 max-w-[180px];
}
diff --git a/web/components/ui/Tooltip.tsx b/web/components/ui/Tooltip.tsx
index 4313de2be..c79851942 100644
--- a/web/components/ui/Tooltip.tsx
+++ b/web/components/ui/Tooltip.tsx
@@ -1,6 +1,13 @@
"use client";
-import { ReactNode, useState, useCallback, useRef, useId } from "react";
+import {
+ ReactNode,
+ useState,
+ useCallback,
+ useEffect,
+ useRef,
+ useId,
+} from "react";
interface TooltipProps {
label: string;
@@ -24,17 +31,28 @@ export function Tooltip({
timeoutRef.current = setTimeout(() => setVisible(true), 300);
}, []);
+ const showNow = useCallback(() => {
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
+ setVisible(true);
+ }, []);
+
const hideTooltip = useCallback(() => {
if (timeoutRef.current) clearTimeout(timeoutRef.current);
setVisible(false);
}, []);
+ useEffect(() => {
+ return () => {
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
+ };
+ }, []);
+
return (
<div
className="tooltip-wrapper"
onMouseEnter={showTooltip}
onMouseLeave={hideTooltip}
- onFocus={showTooltip}
+ onFocus={showNow}
onBlur={hideTooltip}
aria-describedby={visible ? tooltipId : undefined}
>