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

Merge pull request #1477 #1478

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/components/Header/mobile_header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sendGAEvent } from "@next/third-parties/google"
import { Fragment, useEffect, useState } from "react"
import { Fragment, useEffect, useLayoutEffect, useState } from "react"

import { Box, Collapse, List, Stack } from "@mui/material"
import { styled } from "@mui/system"
Expand Down Expand Up @@ -39,14 +39,22 @@ const MobileHeader = ({ currentMenu }) => {
setActiveCollapse(currentMenu[1])
}, [currentMenu])

const toggleDrawer = isOpen => {
setOpen(isOpen)
if (isOpen) {
useLayoutEffect(() => {
if (open) {
window.document.body.classList.add("mobile-top-nav-open")
} else {
window.document.body.classList.remove("mobile-top-nav-open")
setActiveCollapse(currentMenu[1])
}
}, [open])

const handleCloseMobileHeader = () => {
if (open) {
setOpen(false)
}
}

const handleToggleMobileHeader = () => {
setOpen(!open)
}

const toggleCollapse = collapse => {
Expand All @@ -58,7 +66,6 @@ const MobileHeader = ({ currentMenu }) => {
label,
device: "mobile",
})
toggleDrawer(false)
}

const renderList = () => (
Expand Down Expand Up @@ -133,7 +140,7 @@ const MobileHeader = ({ currentMenu }) => {
>
<Stack sx={{ height: "6.4rem", px: "2rem", lineHeight: "3rem" }} direction="row" justifyContent="space-between" alignItems="center">
<Link href="/" className="flex">
<Box onClick={() => toggleDrawer(false)}>
<Box onClick={handleCloseMobileHeader}>
<Logo light={dark} />
</Box>
</Link>
Expand All @@ -154,7 +161,7 @@ const MobileHeader = ({ currentMenu }) => {
transform: "rotate(-45deg) translate(5px, -5px)",
},
}}
onClick={() => toggleDrawer(!open)}
onClick={handleToggleMobileHeader}
className={open ? "active" : ""}
>
<Bar dark={dark}></Bar>
Expand Down