Skip to content

Commit 6204480

Browse files
committed
fix: Position mobile menu above footer using CSS
This commit addresses the issue with the mobile menu in LayoutMobileMenu.vue by implementing a CSS-based solution to position the menu above the footer. The changes include: Remove JavaScript-based height calculations Add CSS positioning for the mobile menu to prevent footer overlap Simplify component logic for toggling menu visibility Ensure menu is scrollable when content exceeds available height Maintain proper opening and closing functionality The mobile menu now extends from the top of the screen to just above the footer, allowing users to close it by clicking the hamburger icon or selecting a menu item. The footer remains visible and accessible at all times. Note: The CSS values for bottom spacing and max-height may need adjustment based on the actual footer height in the application. This fix improves the user experience by ensuring the mobile menu is always accessible and doesn't interfere with the footer content.
1 parent fae2c0b commit 6204480

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

components/Layout/LayoutMobileMenu.vue

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
<template>
22
<div class="relative">
3-
<div
4-
v-if="!firstRender"
5-
class="fixed top-0 left-0 h-[580px] w-screen mt-4 z-0 bg-white animate__animated"
6-
:class="{
7-
animate__fadeInLeft: expandedMenu,
8-
animate__fadeOutRight: !expandedMenu && !firstRender,
9-
}"
3+
<Transition
4+
enter-active-class="animate__animated animate__fadeInLeft"
5+
leave-active-class="animate__animated animate__fadeOutRight"
106
>
11-
<ul>
12-
<li class="text-xl linkStyle">
13-
<NuxtLink to="/" @click="displayMobileMenu"> Home </NuxtLink>
14-
</li>
15-
<li class="text-xl linkStyle">
16-
<NuxtLink to="/products" @click="displayMobileMenu">
17-
Products
18-
</NuxtLink>
19-
</li>
20-
<li class="text-xl linkStyle">
21-
<NuxtLink to="/categories" @click="displayMobileMenu">
22-
Categories
23-
</NuxtLink>
24-
</li>
25-
<li class="text-xl linkStyle">
26-
<NuxtLink to="/search" @click="displayMobileMenu"> Search </NuxtLink>
27-
</li>
28-
</ul>
29-
</div>
7+
<div
8+
v-if="expandedMenu"
9+
ref="mobileMenu"
10+
class="fixed left-0 w-screen z-10 bg-white overflow-y-auto mobile-menu"
11+
>
12+
<ul>
13+
<li class="text-xl linkStyle">
14+
<NuxtLink to="/" @click="displayMobileMenu"> Home </NuxtLink>
15+
</li>
16+
<li class="text-xl linkStyle">
17+
<NuxtLink to="/products" @click="displayMobileMenu">
18+
Products
19+
</NuxtLink>
20+
</li>
21+
<li class="text-xl linkStyle">
22+
<NuxtLink to="/categories" @click="displayMobileMenu">
23+
Categories
24+
</NuxtLink>
25+
</li>
26+
<li class="text-xl linkStyle">
27+
<NuxtLink to="/search" @click="displayMobileMenu"> Search </NuxtLink>
28+
</li>
29+
</ul>
30+
</div>
31+
</Transition>
3032
<div class="w-5/12 lg:hidden" />
3133
<div class="flex flex-row w-2/12 px-2 my-2 lg:hidden">
3234
<div class="self-center block w-full mr-4">
@@ -48,16 +50,24 @@
4850
</template>
4951

5052
<script setup>
53+
import { ref } from 'vue'
54+
5155
const expandedMenu = useState("expandedMenu", () => false);
52-
const firstRender = useState("firstRender", () => true);
56+
const mobileMenu = ref(null);
5357
5458
const displayMobileMenu = () => {
5559
expandedMenu.value = !expandedMenu.value;
56-
firstRender.value = false;
5760
};
5861
</script>
5962

6063
<style scoped>
64+
/* Mobile menu positioning */
65+
.mobile-menu {
66+
top: 0;
67+
bottom: 80px; /* Adjust this value to match your footer height */
68+
max-height: calc(100vh - 80px); /* Adjust this value to match your footer height */
69+
}
70+
6171
/* Style for mobile menu links */
6272
.linkStyle {
6373
@apply w-auto p-4 m-4 font-bold text-center border border-gray-300 border-opacity-50 shadow-md rounded;

0 commit comments

Comments
 (0)