fix(mobile): dynamically bind drawer slide origin to actual burger button viewport position
Deploy Frontend / deploy (push) Successful in 1m26s
Deploy Frontend / deploy (push) Successful in 1m26s
This commit is contained in:
1 parent
5400fd360a
commit
bc8100b517
2 files changed
+36
-4
No files matched your search
@@ -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 */}
|
||||
<div
|
||||
className={`fixed top-0 bottom-0 z-[9999] flex h-[100dvh] w-[300px] max-w-[85vw] flex-col justify-between bg-zinc-900 dark:bg-zinc-950 text-white shadow-2xl transition-transform duration-300 ease-out overflow-y-auto ${
|
||||
isRTL
|
||||
side === "left"
|
||||
? `left-0 border-r border-white/10 ${clicked ? "translate-x-0" : "-translate-x-full"}`
|
||||
: `right-0 border-l border-white/10 ${clicked ? "translate-x-0" : "translate-x-full"}`
|
||||
}`}
|
||||
|
||||
@@ -34,11 +34,27 @@ export default function MobileMenu({ clicked, setClicked }: 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) {
|
||||
@@ -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 */}
|
||||
<div
|
||||
className={`fixed top-0 bottom-0 z-[9999] flex h-[100dvh] w-[300px] max-w-[85vw] flex-col justify-between bg-zinc-900 dark:bg-zinc-950 text-white shadow-2xl transition-transform duration-300 ease-out overflow-y-auto ${
|
||||
isRTL
|
||||
side === "left"
|
||||
? `left-0 border-r border-white/10 ${clicked ? "translate-x-0" : "-translate-x-full"}`
|
||||
: `right-0 border-l border-white/10 ${clicked ? "translate-x-0" : "translate-x-full"}`
|
||||
}`}
|
||||
|
||||
Reference in new issue
Block a user