diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index 56e6091fc..29f92564a 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -18,7 +18,7 @@ import { Text, } from '@radix-ui/themes'; import Link from 'next/link'; -import { Suspense, useEffect, useState } from 'react'; +import { Suspense, useEffect, useRef, useState } from 'react'; import * as styles from '../../app/page.css'; import { REGIONS, UNLOCALIZED_REGION_NAMES } from '../../constants/regions'; import { TOOLS } from '../../constants/tools'; @@ -37,7 +37,8 @@ export const NAVBAR_HEIGHT = 64; export default function Navbar() { const wideFormat = useWideFormat(480); const login = useApp((state) => state.login); - const [showHamburgerMenu, setShowHamburgerMenu] = useState(true); + const [showHamburgerMenu, setShowHamburgerMenu] = useState(false); + const navbar = useRef(null); useEffect(() => { if (!login) return; @@ -85,164 +86,177 @@ export default function Navbar() { ); return ( - <> - setShowHamburgerMenu(true)} - onPointerLeave={() => setShowHamburgerMenu(false)} - > - - setShowHamburgerMenu(true)} + onPointerLeave={(event) => { + if ( + navbar.current === + document.elementFromPoint(event.clientX, event.clientY) + ) { + // false positive bug: https://stackoverflow.com/a/45267167/12294756 + return; + } + + setShowHamburgerMenu(false); + }} + onFocus={() => setShowHamburgerMenu(true)} + onBlur={() => setShowHamburgerMenu(false)} + > + + + setShowHamburgerMenu((state) => !state)} > - setShowHamburgerMenu((state) => !state)} - > - {showHamburgerMenu ? : } - + {showHamburgerMenu ? : } + - setShowHamburgerMenu(false)} - href="/" - style={{ - color: 'inherit', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }} - > - - + setShowHamburgerMenu(false)} + href="/" + style={{ + color: 'inherit', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }} + > + + -
+
- {wideFormat && plugs} + {wideFormat && plugs} - setShowHamburgerMenu(false)}> - + setShowHamburgerMenu(false)}> + + + + + + + + {login && ( + + - + - - + - {login && ( - - - - - - + + + }> + + + + + + )} - - - }> - - - - - - )} + {/* TODO: re-enable in the future */} + {!login && false && ( + + + + - {/* TODO: re-enable in the future */} - {!login && false && ( - - - - - - - - Choose your region - - - {REGIONS.map((region) => ( - setShowHamburgerMenu(false)} - key={region} - href={authURL( - region, - typeof window === 'undefined' - ? undefined - : location.href, - )} - > - {UNLOCALIZED_REGION_NAMES[region]} - - ))} - - - - - )} - - - - {TOOLS.filter((tool) => !tool.href).map((tool) => ( - setShowHamburgerMenu(false)} > - - {tool.title} - - - ))} - + + Choose your region + + + {REGIONS.map((region) => ( + setShowHamburgerMenu(false)} + key={region} + href={authURL( + region, + typeof window === 'undefined' + ? undefined + : location.href, + )} + > + {UNLOCALIZED_REGION_NAMES[region]} + + ))} + + + + + )} - - + + + {TOOLS.filter((tool) => !tool.href).map((tool) => ( + setShowHamburgerMenu(false)} + > + + {tool.title} + + + ))} + + + ); }