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(navbar): on Mobile Screen Navbar remains open even page is changed #1247

Merged
Merged
11 changes: 9 additions & 2 deletions src/components/Navbar/NavbarLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import type { ComponentProps, ElementType, FC } from 'react';
import type { ComponentProps, ElementType, FC, MouseEvent } from 'react';
import { twMerge } from 'tailwind-merge';
import { mergeDeep } from '../../helpers/merge-deep';
import type { DeepPartial } from '../../types';
Expand Down Expand Up @@ -28,12 +28,18 @@ export const NavbarLink: FC<NavbarLinkProps> = ({
children,
className,
theme: customTheme = {},
onClick,
...props
}) => {
const { theme: rootTheme } = useNavbarContext();
const { theme: rootTheme, setIsOpen } = useNavbarContext();

const theme = mergeDeep(rootTheme.link, customTheme);

const handleClick = (event: MouseEvent<HTMLAnchorElement>) => {
setIsOpen(false);
onClick?.(event);
};

return (
<li>
<Component
Expand All @@ -44,6 +50,7 @@ export const NavbarLink: FC<NavbarLinkProps> = ({
theme.disabled[disabled ? 'on' : 'off'],
className,
)}
onClick={handleClick}
dhavalveera marked this conversation as resolved.
Show resolved Hide resolved
{...props}
>
{children}
Expand Down
Loading