diff --git a/src/app/(routes)/blog/components/mobile-menu/mobileMenu.tsx b/src/app/(routes)/blog/components/mobile-menu/mobileMenu.tsx index 0c46423..5613d3a 100644 --- a/src/app/(routes)/blog/components/mobile-menu/mobileMenu.tsx +++ b/src/app/(routes)/blog/components/mobile-menu/mobileMenu.tsx @@ -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 = ( +