From bc8100b517116650534e3678a38ac608d989106f Mon Sep 17 00:00:00 2001 From: Parsa Aghayi Date: Mon, 2 Nov 2026 14:03:16 +0000 Subject: [PATCH] fix(mobile): dynamically bind drawer slide origin to actual burger button viewport position --- .../components/mobile-menu/mobileMenu.tsx | 20 +++++++++++++++++-- .../components/mobile-menu/mobileMenu.tsx | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/app/(routes)/(website)/components/mobile-menu/mobileMenu.tsx b/src/app/(routes)/(website)/components/mobile-menu/mobileMenu.tsx index 5dbf5f5..50f8dce 100644 --- a/src/app/(routes)/(website)/components/mobile-menu/mobileMenu.tsx +++ b/src/app/(routes)/(website)/components/mobile-menu/mobileMenu.tsx @@ -36,11 +36,27 @@ export default function MobileMenu({ clicked, setClicked, dict }: PropsType) { const router = useRouter(); const selectedLocale = useSelectedLocale(); const isRTL = selectedLocale === "fa"; + const [side, setSide] = useState<"left" | "right">("right"); useEffect(() => { setMounted(true); }, []); + // Detect which side the burger button is actually located on the screen + useEffect(() => { + const updateSide = () => { + const btn = document.querySelector('button[aria-label="Toggle navigation menu"]'); + if (btn) { + const rect = btn.getBoundingClientRect(); + const isLeft = rect.left + rect.width / 2 < window.innerWidth / 2; + setSide(isLeft ? "left" : "right"); + } + }; + updateSide(); + window.addEventListener("resize", updateSide); + return () => window.removeEventListener("resize", updateSide); + }, [clicked, isRTL]); + // Prevent background scrolling when mobile menu is open useEffect(() => { if (clicked) { @@ -93,10 +109,10 @@ export default function MobileMenu({ clicked, setClicked, dict }: PropsType) { aria-hidden="true" /> - {/* Full Height Solid Drawer - slides from the same side as the burger button */} + {/* Full Height Solid Drawer - strictly aligned to burger button side */}
("right"); useEffect(() => { setMounted(true); }, []); + // Detect which side the burger button is actually located on the screen + useEffect(() => { + const updateSide = () => { + const btn = document.querySelector('button[aria-label="Toggle navigation menu"]'); + if (btn) { + const rect = btn.getBoundingClientRect(); + const isLeft = rect.left + rect.width / 2 < window.innerWidth / 2; + setSide(isLeft ? "left" : "right"); + } + }; + updateSide(); + window.addEventListener("resize", updateSide); + return () => window.removeEventListener("resize", updateSide); + }, [clicked, isRTL]); + // Prevent background scrolling when mobile menu is open useEffect(() => { if (clicked) { @@ -106,10 +122,10 @@ export default function MobileMenu({ clicked, setClicked }: PropsType) { aria-hidden="true" /> - {/* Full Height Solid Drawer */} + {/* Full Height Solid Drawer - strictly aligned to burger button side */}