Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed a bug. #212

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions components/Navbar/navbar.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,6 +12,19 @@ function Navbar() {
const isTablet = useMediaQuery({ maxWidth: '1118px' });
const [drop, setDrop] = useState(false);
const [show, setShow] = useState(null);
useEffect(() => {
function handleOutsideClick(event) {
console.log(event.target.closest('.subMenu'))
if (show && !event.target.closest('.subMenu')) {
setShow(false);
}
}

document.addEventListener('mousedown', handleOutsideClick);
return () => {
document.removeEventListener('mousedown', handleOutsideClick);
};
}, [show]);
return (
<div className='container flex justify-center items-center sticky top-0 backdrop-blur z-[99]'>
<div className='w-[1131px]'>
Expand Down Expand Up @@ -43,11 +56,11 @@ function Navbar() {
onClick={() =>
show === link.title ? setShow(null) : setShow(link.title)
}
className='text-[#F0F4F5] ml-16 text-[15px] cursor-pointer relative flex flex-col'
className='text-[#F0F4F5] ml-16 text-[15px] group cursor-pointer relative flex flex-col'
>
<div>
{link.subMenu ? (
<div className='flex items-center'>
<div className='flex items-center '>
{link.title}{' '}
{link.subMenu && (
<Dropdown
Expand All @@ -61,7 +74,7 @@ function Navbar() {
)}
</div>
{show && show === link.title && link.subMenu && (
<div className='absolute z-[9] mt-8 w-[140px] rounded-md left-[-15px] gradient-bg pl-2 pt-1 flex flex-col justify-center space-y-0'>
<div className='subMenu absolute group-hover:bg-red-300 z-[9] mt-8 w-[140px] rounded-md left-[-15px] gradient-bg pl-2 pt-1 flex flex-col justify-center space-y-0'>
{link.subMenu.map((subL) => (
<Link href={subL.ref} key={subL.title}>
<div className='h-[32px] text-[16px]'>
Expand Down
Loading