Skip to content

Commit f9b8282

Browse files
committed
fix: q on hover
1 parent 9291a9f commit f9b8282

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

src/app/components/TopicsList.tsx

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,10 @@
22

33
import Link from 'next/link';
44
import { topics } from '../constants/topics';
5-
import { useState, useEffect, useRef } from 'react';
5+
import { useState } from 'react';
66

77
export default function TopicsList() {
88
const [hoveredTopic, setHoveredTopic] = useState<string | null>(null);
9-
const tooltipRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});
10-
const buttonRefs = useRef<{ [key: string]: HTMLButtonElement | null }>({});
11-
12-
const setTooltipRef = (id: string) => (el: HTMLDivElement | null) => {
13-
tooltipRefs.current[id] = el;
14-
};
15-
16-
const setButtonRef = (id: string) => (el: HTMLButtonElement | null) => {
17-
buttonRefs.current[id] = el;
18-
};
19-
20-
useEffect(() => {
21-
const handleClickOutside = (event: MouseEvent) => {
22-
if (hoveredTopic) {
23-
const tooltip = tooltipRefs.current[hoveredTopic];
24-
const button = buttonRefs.current[hoveredTopic];
25-
if (tooltip && button &&
26-
!tooltip.contains(event.target as Node) &&
27-
!button.contains(event.target as Node)) {
28-
setHoveredTopic(null);
29-
}
30-
}
31-
};
32-
33-
document.addEventListener('mousedown', handleClickOutside);
34-
return () => {
35-
document.removeEventListener('mousedown', handleClickOutside);
36-
};
37-
}, [hoveredTopic]);
389

3910
return (
4011
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 sm:gap-8">
@@ -48,22 +19,17 @@ export default function TopicsList() {
4819
<h2 className="text-2xl font-staatliches text-white mb-2 pr-10">
4920
{topic.title}
5021
</h2>
51-
<button
52-
ref={setButtonRef(id)}
53-
type="button"
22+
<div
5423
className="absolute top-6 sm:top-8 right-6 sm:right-8 w-8 h-8 rounded-full bg-white/20 hover:bg-white/30 flex items-center justify-center transition-colors border border-white/40"
55-
onClick={(e) => {
56-
e.stopPropagation();
57-
setHoveredTopic(hoveredTopic === id ? null : id);
58-
}}
24+
onMouseEnter={() => setHoveredTopic(id)}
25+
onMouseLeave={() => setHoveredTopic(null)}
5926
>
6027
<span className="text-white text-sm font-medium">?</span>
61-
</button>
28+
</div>
6229
</div>
6330
</Link>
6431

6532
<div
66-
ref={setTooltipRef(id)}
6733
className={`absolute z-10 w-80 p-5 bg-white rounded-xl shadow-xl top-full mt-2 right-0 text-left border-2 border-purple transition-all duration-200 origin-top-right ${
6834
hoveredTopic === id
6935
? 'opacity-100 scale-100 translate-y-0'

0 commit comments

Comments
 (0)