Skip to content
Snippets Groups Projects
Commit 3aa3367d authored by Ahmad Nadil's avatar Ahmad Nadil
Browse files

fix: close navbar on mobile menu click

parent 0ca59f11
Branches
Tags
No related merge requests found
...@@ -21,9 +21,10 @@ import { useState, useEffect } from "react" ...@@ -21,9 +21,10 @@ import { useState, useEffect } from "react"
import { handleGetInfo, handleLogout } from "../../utils/auth" import { handleGetInfo, handleLogout } from "../../utils/auth"
interface MobileProps extends FlexProps { interface MobileProps extends FlexProps {
onOpen: () => void onOpen: () => void
onClose: () => void
} }
const MobileNav = ({ onOpen, ...rest }: MobileProps) => { const MobileNav = ({ onOpen, onClose, ...rest }: MobileProps) => {
const navigate = useNavigate() const navigate = useNavigate()
const [userInfo, setUserInfo] = useState({ const [userInfo, setUserInfo] = useState({
user_id: 0, user_id: 0,
...@@ -109,7 +110,13 @@ const MobileNav = ({ onOpen, ...rest }: MobileProps) => { ...@@ -109,7 +110,13 @@ const MobileNav = ({ onOpen, ...rest }: MobileProps) => {
borderColor={useColorModeValue("gray.200", "gray.700")} borderColor={useColorModeValue("gray.200", "gray.700")}
> >
<MenuItem>Profile</MenuItem> <MenuItem>Profile</MenuItem>
<MenuItem>Settings</MenuItem> <MenuItem
onClick={() => {
onClose()
}}
>
Settings
</MenuItem>
<MenuDivider /> <MenuDivider />
<Link <Link
to="/login" to="/login"
......
...@@ -5,10 +5,11 @@ interface NavItemProps extends FlexProps { ...@@ -5,10 +5,11 @@ interface NavItemProps extends FlexProps {
icon: IconType icon: IconType
children: React.ReactNode children: React.ReactNode
link: string link: string
onClick?: () => void
} }
const NavItem = ({ icon, children, link, ...rest }: NavItemProps) => { const NavItem = ({ icon, children, link, onClick, ...rest }: NavItemProps) => {
return ( return (
<Link to={link}> <Link to={link} onClick={onClick}>
<Box style={{ textDecoration: "none" }} _focus={{ boxShadow: "none" }}> <Box style={{ textDecoration: "none" }} _focus={{ boxShadow: "none" }}>
<Flex <Flex
align="center" align="center"
......
...@@ -30,7 +30,7 @@ const Sidebar = ({ children }: { children: ReactNode }) => { ...@@ -30,7 +30,7 @@ const Sidebar = ({ children }: { children: ReactNode }) => {
<SidebarContent onClose={onClose} /> <SidebarContent onClose={onClose} />
</DrawerContent> </DrawerContent>
</Drawer> </Drawer>
<MobileNav onOpen={onOpen} /> <MobileNav onOpen={onOpen} onClose={onClose} />
<Box ml={{ base: 0, md: 60 }} p="4"> <Box ml={{ base: 0, md: 60 }} p="4">
{children} {children}
</Box> </Box>
......
...@@ -75,7 +75,7 @@ const SidebarContent = ({ onClose, ...rest }: SidebarProps) => { ...@@ -75,7 +75,7 @@ const SidebarContent = ({ onClose, ...rest }: SidebarProps) => {
<CloseButton display={{ base: "flex", md: "none" }} onClick={onClose} /> <CloseButton display={{ base: "flex", md: "none" }} onClick={onClose} />
</Flex> </Flex>
{LinkItems.map((item) => ( {LinkItems.map((item) => (
<NavItem key={item.name} icon={item.icon} link={item.link}> <NavItem key={item.name} icon={item.icon} link={item.link} onClick={onClose}>
{item.name} {item.name}
</NavItem> </NavItem>
))} ))}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment