diff --git a/front/src/components/Header.tsx b/front/src/components/Header.tsx index e74efd8..6156cc4 100644 --- a/front/src/components/Header.tsx +++ b/front/src/components/Header.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useRef } from "react"; import Image from "next/image"; import Logo from '@/assets/logo_vermelha.png'; import Link from 'next/link'; @@ -14,6 +14,8 @@ export function Header() { const [accessibilityMenuOpen, setAccessibilityMenuOpen] = useState(false); const [keepMenuOpen, setKeepMenuOpen] = useState(false); + const accessibilityMenuRef = useRef(null); + useEffect(() => { const savedDarkMode = localStorage.getItem('darkMode') === 'true'; const savedHighContrast = localStorage.getItem('highContrast') === 'true'; @@ -35,6 +37,24 @@ export function Header() { localStorage.setItem('fontSize', fontSize); }, [darkMode, highContrast, fontSize]); + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (accessibilityMenuRef.current && !accessibilityMenuRef.current.contains(event.target as Node)) { + setAccessibilityMenuOpen(false); + } + }; + + if (accessibilityMenuOpen) { + document.addEventListener('mousedown', handleClickOutside); + } else { + document.removeEventListener('mousedown', handleClickOutside); + } + + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, [accessibilityMenuOpen]); + const toggleNavbar = () => setIsOpen(!isOpen); const increaseFontSize = () => setFontSize('text-lg'); @@ -93,43 +113,43 @@ export function Header() { {accessibilityMenuOpen && ( -
- - - - -
- )} - + + + + + + )}