Skip to content

Commit da559db

Browse files
committed
feat: fixed navbar closing dropdown bug
1 parent b2ef77e commit da559db

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

src/components/Navbar/index.jsx

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
1-
import { useState, useContext } from "react";
1+
import { useState } from "react";
22
import { Link, useLocation } from "react-router-dom";
33
import PropTypes from "prop-types";
44
import Logo from "@/assets/images/logo.svg";
55
import closeIcon from "@/assets/images/close.svg";
66
import menuIcon from "@/assets/images/menu.svg";
7-
import { CursorVariantContext } from "@/context/CursorVariantProvider";
87

98
function Navbar({ links }) {
109
const [isOpen, setIsOpen] = useState(false);
1110
const location = useLocation();
1211

13-
const { setCursorVariantNone, setCursorVariantDefault } =
14-
useContext(CursorVariantContext);
12+
const handleLinkClick = () => {
13+
setIsOpen(false);
14+
};
1515

1616
return (
17-
<nav
18-
className={`shadow-md w-full flex xs:flex-col md:flex-row ${isOpen ? "xs:h-screen" : ""} md:h-full justify-between items-center px-6 bg-secondary-dark`}
19-
>
20-
<div className="flex flex-row justify-between xs:w-full md:w-auto items-center">
21-
<Link
22-
to="/"
23-
className="cursor-pointer"
24-
onMouseEnter={setCursorVariantNone}
25-
onMouseLeave={setCursorVariantDefault}
26-
>
27-
<img src={Logo} className="w-[10rem]" alt="logo" />
28-
</Link>
29-
<button
30-
type="button"
31-
onClick={() => setIsOpen(!isOpen)}
32-
className="w-7 h-7 text-white cursor-pointer md:hidden"
33-
>
34-
{isOpen ? (
35-
<img src={closeIcon} alt="close" />
36-
) : (
37-
<img src={menuIcon} alt="menu" />
38-
)}
39-
</button>
40-
</div>
17+
<nav className="shadow-md w-full flex flex-wrap justify-between items-center px-6 bg-secondary-dark relative">
18+
<Link to="/" className="cursor-pointer">
19+
<img src={Logo} alt="logo" />
20+
</Link>
21+
22+
<button
23+
type="button"
24+
onClick={() => setIsOpen(!isOpen)}
25+
className="w-7 h-7 text-white cursor-pointer md:hidden"
26+
>
27+
{isOpen ? (
28+
<img src={closeIcon} alt="close" />
29+
) : (
30+
<img src={menuIcon} alt="menu" />
31+
)}
32+
</button>
33+
4134
<ul
4235
className={`
43-
md:flex pl-0 justify-start md:justify-center md:items-center md:pb-0 md:z-auto left-0 xs:justify-center xs:gap-y-12
44-
${isOpen ? "flex flex-col grow" : "hidden"}
36+
pl-0 justify-start md:justify-center
37+
md:flex md:items-center md:w-auto w-full md:pb-0 pb-12 md:static
38+
absolute md:bg-transparent bg-secondary-dark md:z-auto z-50 left-0
39+
transition-all duration-500 ease-in ${isOpen ? "top-full" : "top-[-490px]" }
4540
`}
46-
onMouseEnter={setCursorVariantNone}
47-
onMouseLeave={setCursorVariantDefault}
4841
>
4942
{links.map((link) => (
5043
<li
5144
key={link.name}
52-
className={`
53-
group font-regular text-white md:my-0 md:ml-8 transition-all hover:text-primary
54-
`}
45+
className="md:ml-8 md:my-0 my-7 font-semibold relative"
5546
>
56-
<Link to={link.path}>{link.name}</Link>
57-
<span
58-
className={`block group-hover:max-w-full transition-all duration-500 h-0.5 bg-primary rounded ${
59-
location.pathname
60-
.toLowerCase()
61-
.includes(link.path.toLowerCase())
62-
? "w-full"
63-
: "max-w-0"
64-
}`}
65-
/>
47+
<Link
48+
to={link.path}
49+
className={`
50+
text-white text-center block px-3 py-2 relative
51+
after:content-[''] after:absolute after:bottom-0 after:left-0 after:w-full after:h-0.5
52+
after:bg-red-500 after:transition-all after:duration-300 after:scale-x-0 after:origin-left
53+
hover:after:scale-x-100
54+
${
55+
location.pathname
56+
.toLowerCase()
57+
.includes(link.path.toLowerCase())
58+
? "w-full"
59+
: "max-w-0"
60+
}
61+
`}
62+
onClick={handleLinkClick}
63+
>
64+
{link.name}
65+
</Link>
6666
</li>
6767
))}
6868
</ul>

0 commit comments

Comments
 (0)