Skip to content

Commit

Permalink
fixing blinking menu bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Nov 14, 2023
1 parent 37a129a commit 23efb7e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/UI/desktopNav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent, MouseEvent, useEffect, useRef } from "react";
import React, { FunctionComponent, MouseEvent, useEffect } from "react";
import styles from "../../styles/components/desktopNav.module.css";
import Link from "next/link";
import { FaDiscord, FaGithub, FaTwitter } from "react-icons/fa";
Expand All @@ -9,15 +9,15 @@ type DesktopNavProps = {
};

const DesktopNav: FunctionComponent<DesktopNavProps> = ({ close }) => {
const ref = useRef<HTMLDivElement>(null);
const handleClick = (e: MouseEvent) => {
e.stopPropagation();
};

// Close when clicking outside the nav
useEffect(() => {
const handleClickOutside: EventListener = (e) => {
if (ref.current && !ref.current.contains(e.target as Node)) {
const burger = document.getElementById("burger");
if (burger && !burger.contains(e.target as Node)) {
close();
}
};
Expand All @@ -27,9 +27,10 @@ const DesktopNav: FunctionComponent<DesktopNavProps> = ({ close }) => {
// Unbind the event listener on clean up
document.removeEventListener("mousedown", handleClickOutside);
};
}, [ref]);
}, []);

return (
<nav onClick={handleClick} className={styles.navContainer} ref={ref}>
<nav onClick={handleClick} className={styles.navContainer}>
<div className={styles.columns}>
<div className={styles.column}>
<Link
Expand Down

0 comments on commit 23efb7e

Please sign in to comment.