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 */}