From aa0a693514224d6fe61a6ee06ede8eef1e59d9c3 Mon Sep 17 00:00:00 2001 From: Shashwat Pratap Singh <114943221+ShashwatPS@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:52:15 +0530 Subject: [PATCH] fix: fixed the venue sub menu not closing (#248) * Fixed the closing issue * Fixed errors --------- Co-authored-by: Ace <40604284+AceTheCreator@users.noreply.github.com> --- components/Navbar/navbar.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/components/Navbar/navbar.js b/components/Navbar/navbar.js index 59ec489c..148d1da7 100644 --- a/components/Navbar/navbar.js +++ b/components/Navbar/navbar.js @@ -1,6 +1,6 @@ import Link from 'next/link'; import Dropdown from '../illustration/dropdown'; -import { useState } from 'react'; +import { useState,useEffect } from 'react'; import links from '../../config/links.json'; import NavDrop from './navDrop'; import Hamburger from '../illustration/hamburger'; @@ -8,10 +8,19 @@ import { useMediaQuery } from 'react-responsive'; import Cancel from '../illustration/cancel'; + function Navbar() { const isTablet = useMediaQuery({ maxWidth: '1118px' }); const [drop, setDrop] = useState(false); const [show, setShow] = useState(null); + function handleClosing(event) { + if (show && !event.target.closest('.subMenu')) { + setShow(false); + } + } + useEffect(() => { + document.addEventListener('mousedown', handleClosing); + }, [show]); return (