Skip to content

Commit

Permalink
style: close navbar when link is clicked in mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
premagarwals committed Nov 15, 2024
1 parent 8b66256 commit e8fbc84
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ const Navbar = () => {
);
}, [location.pathname]);

function closeNavbar() {
const element = document.getElementById('linkList');

if (element) {
element.addEventListener('click', () => {
element.classList.remove('open');
});
}
setIsOpen(false);
}

return (
<div className='navbar'>
<div className='light-logo'>
Expand All @@ -91,10 +102,10 @@ const Navbar = () => {
<div className="dots dot6"></div>
</div>
</div>
<ul className={`link-container ${isOpen ? 'open' : ''}`}>
<ul id="linkList" className={`link-container ${isOpen ? 'open' : ''}`}>
{LINKS.map((link) => (
<li key={link.name}>
<Link to={link.link} className={link.isActive ? `link nav-glow` : `link`}>
<Link to={link.link} className={link.isActive ? `link nav-glow` : `link`} onClick={() => { closeNavbar() }}>
{link.name}
</Link>
</li>
Expand Down

0 comments on commit e8fbc84

Please sign in to comment.