fix(blog): portal mobile menu to document.body with solid backdrop and full height drawer
Deploy Frontend / deploy (push) Successful in 1m25s

This commit is contained in:
Parsa Aghayi committed 2026-11-02 13:32:05 +00:00
1 parent 7ba29d290f
commit de6597a6fd
1 file changed
+51 -18
@@ -3,7 +3,19 @@
import Image from "next/image";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { X, Globe, ArrowLeft, ArrowRight, Home, Flame, Clock, Grid, BookOpen } from "lucide-react";
import { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import {
X,
Globe,
ArrowLeft,
ArrowRight,
Home,
Flame,
Clock,
Grid,
BookOpen,
} from "lucide-react";
import {
setSelectedLocale,
@@ -17,11 +29,28 @@ type PropsType = {
};
export default function MobileMenu({ clicked, setClicked }: PropsType) {
const [mounted, setMounted] = useState(false);
const pathname = usePathname();
const router = useRouter();
const selectedLocale = useSelectedLocale();
const isRTL = selectedLocale === "fa";
useEffect(() => {
setMounted(true);
}, []);
// Prevent background scrolling when mobile menu is open
useEffect(() => {
if (clicked) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = "";
}
return () => {
document.body.style.overflow = "";
};
}, [clicked]);
const handleLocaleChange = (locale: "fa" | "en") => {
try {
const url = new URL(window.location.href);
@@ -64,20 +93,22 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) {
},
];
return (
<>
{/* Backdrop */}
if (!mounted) return null;
const content = (
<div className="lg:hidden" dir={isRTL ? "rtl" : "ltr"}>
{/* Full viewport Backdrop */}
<div
className={`fixed inset-0 z-[60] bg-black/70 backdrop-blur-sm transition-opacity duration-300 lg:hidden ${
className={`fixed inset-0 z-[9998] bg-black/80 backdrop-blur-sm transition-opacity duration-300 ${
clicked ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"
}`}
onClick={closeMenu}
aria-hidden="true"
/>
{/* Drawer */}
{/* Full Height Solid Drawer */}
<div
className={`fixed top-0 start-0 z-[70] flex h-full w-[290px] max-w-[85vw] flex-col justify-between border-e border-border bg-card dark:bg-zinc-950 text-card-foreground shadow-2xl transition-transform duration-300 ease-out lg:hidden ${
className={`fixed top-0 bottom-0 start-0 z-[9999] flex h-[100dvh] w-[300px] max-w-[85vw] flex-col justify-between border-e border-border/80 bg-zinc-900 dark:bg-zinc-950 text-white shadow-2xl transition-transform duration-300 ease-out overflow-y-auto ${
clicked
? "translate-x-0"
: isRTL
@@ -87,9 +118,9 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) {
>
{/* Header */}
<div>
<div className="flex items-center justify-between border-b border-border/60 px-5 py-4">
<div className="flex items-center justify-between border-b border-white/10 px-5 py-4">
<Link href="/blog" onClick={closeMenu} className="flex items-center">
<div className="relative h-[32px] w-[140px] dark:brightness-0 dark:invert transition-all">
<div className="relative h-[32px] w-[140px] brightness-0 invert transition-all">
<Image
src="/images/blog/logo/logo-no-background.png"
fill
@@ -102,7 +133,7 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) {
<button
onClick={closeMenu}
aria-label="Close menu"
className="flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
className="flex h-9 w-9 items-center justify-center rounded-lg text-zinc-400 transition-colors hover:bg-white/10 hover:text-white"
>
<X className="h-5 w-5" />
</button>
@@ -123,11 +154,11 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) {
onClick={closeMenu}
className={`flex items-center gap-3 rounded-xl px-4 py-3 text-sm font-medium transition-all ${
isActive
? "bg-primary/10 text-primary font-semibold"
: "text-muted-foreground hover:bg-muted/60 hover:text-foreground"
? "bg-primary text-primary-foreground font-semibold shadow-sm"
: "text-zinc-300 hover:bg-white/10 hover:text-white"
}`}
>
<Icon className={`h-4 w-4 ${isActive ? "text-primary" : "text-muted-foreground"}`} />
<Icon className={`h-4 w-4 ${isActive ? "text-primary-foreground" : "text-zinc-400"}`} />
<span>{link.label}</span>
</Link>
);
@@ -136,30 +167,32 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) {
</div>
{/* Footer Area with Language Switcher and Portfolio Link */}
<div className="border-t border-border/60 p-4 space-y-3">
<div className="border-t border-white/10 p-4 space-y-3 bg-zinc-950/40">
<Link
href="/"
onClick={closeMenu}
className="flex items-center justify-between w-full rounded-xl bg-muted/50 hover:bg-muted px-4 py-3 text-xs font-semibold text-foreground transition-colors"
className="flex items-center justify-between w-full rounded-xl bg-white/5 hover:bg-white/10 px-4 py-3 text-xs font-semibold text-white transition-colors"
>
<span>{isRTL ? "بازگشت به سایت اصلی و رزومه" : "Back to Main Portfolio"}</span>
{isRTL ? <ArrowLeft className="h-4 w-4" /> : <ArrowRight className="h-4 w-4" />}
</Link>
<div className="flex items-center justify-between w-full rounded-xl border border-border bg-card px-3 py-2 text-xs font-medium text-foreground">
<div className="flex items-center justify-between w-full rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs font-medium text-white">
<span>{isRTL ? "حالت تم (تیره / روشن)" : "Theme Mode"}</span>
<ThemeToggle />
</div>
<button
onClick={() => handleLocaleChange(selectedLocale === "fa" ? "en" : "fa")}
className="flex items-center justify-center gap-2 w-full rounded-xl border border-border bg-card hover:bg-muted/60 py-2.5 text-xs font-medium text-foreground transition-all"
className="flex items-center justify-center gap-2 w-full rounded-xl border border-white/10 bg-white/5 hover:bg-white/10 py-2.5 text-xs font-medium text-white transition-all"
>
<Globe className="h-4 w-4 text-primary" />
<span>{selectedLocale === "fa" ? "English Version" : "نسخه فارسی"}</span>
</button>
</div>
</div>
</>
</div>
);
return createPortal(content, document.body);
}