Skip to content

Commit 4e8f1d9

Browse files
committed
fix: navLinks does't scroll to desire section
1 parent 27d5b3c commit 4e8f1d9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/components/NavigationMenu.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import clsx from 'clsx';
2+
import { MouseEvent } from 'react';
23
import { Link } from 'react-router-dom';
34

45
import Button from './Button';
@@ -36,6 +37,17 @@ const NavigationMenu = ({ openState }: { openState: boolean }) => {
3637
element.click();
3738
};
3839

40+
const handelNavigation = (e: MouseEvent<HTMLAnchorElement>) => {
41+
e.preventDefault();
42+
const path = (e.target as HTMLAnchorElement).getAttribute('href');
43+
if (!path) return;
44+
document.querySelector(path)?.scrollIntoView({
45+
behavior: 'smooth',
46+
block: 'start',
47+
inline: 'start',
48+
});
49+
};
50+
3951
return (
4052
<>
4153
{/* Desktop Navbar */}
@@ -44,9 +56,13 @@ const NavigationMenu = ({ openState }: { openState: boolean }) => {
4456
<ul className="flex gap-4">
4557
{menuItems.map(item => (
4658
<li key={item.id}>
47-
<Link to={item.path} className="font-medium text-white">
59+
<a
60+
href={item.path}
61+
className="font-medium text-white"
62+
onClick={handelNavigation}
63+
>
4864
{item.itemName}
49-
</Link>
65+
</a>
5066
</li>
5167
))}
5268
</ul>

0 commit comments

Comments
 (0)