fix: lock body scroll while menu is open, scroll menu internally
Per the user's request: - Page scroll is locked when the mobile menu is open: add an :has() selector that applies overflow: hidden + touch-action: none to the <body> when the .nav-main__toggle has aria-expanded=true. Verified with mouse wheel and PageDown: window.scrollY stays at 0. - Menu scrolls internally when its content overflows: switch .menu-vdi's 'overflow-hidden' to 'overflow-y: auto' with 'overscroll-behavior: contain' so scroll gestures feed the menu rather than chain-scroll to the body behind it. - Cap the menu at viewport height instead of growing: change 'min-height: calc(100vh - var(--hgtHeader))' to 'max-height: calc(100vh - var(--hgtHeader))' so the menu fills the visible space below the header and any overflowing items become scrollable inside the menu.
This commit is contained in:
@@ -7,46 +7,69 @@
|
||||
|
||||
/* Mobile accordion navigation */
|
||||
@media screen and (max-width: 62.5rem) {
|
||||
.nav-main {
|
||||
.nav-main__toggle {
|
||||
/* display */
|
||||
@apply text-white p-3;
|
||||
}
|
||||
|
||||
.menu-vdi {
|
||||
@apply flex-col bg-white w-[95%] right-0 z-10 py-6;
|
||||
@apply absolute hidden; /* Hidden by default */
|
||||
top: var(--hgtHeader);
|
||||
min-height: calc(100vh - var(--hgtHeader));
|
||||
|
||||
.menu-vdi__submenu {
|
||||
@apply py-2 px-7 flex-col;
|
||||
}
|
||||
|
||||
.menu-vdi__item {
|
||||
a,
|
||||
button {
|
||||
/* text */
|
||||
@apply font-bold text-20px text-black hover:text-light no-underline leading-snug;
|
||||
/* spacing & display */
|
||||
@apply block w-full p-4;
|
||||
/* interaction */
|
||||
@apply focus-visible:bg-secondary-200 hover:bg-secondary-200;
|
||||
.nav-main {
|
||||
.nav-main__toggle {
|
||||
/* display */
|
||||
@apply text-white p-3;
|
||||
}
|
||||
|
||||
a {
|
||||
@apply block w-full;
|
||||
.menu-vdi {
|
||||
@apply relative right-0 py-8 flex flex-col;
|
||||
@apply absolute hidden; /* Hidden by default */
|
||||
|
||||
/* Allow the menu itself to scroll when content overflows the viewport */
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
|
||||
background: var(--color-cwc-blue-02);
|
||||
color: var(--color-white);
|
||||
/* Cap the menu height to the visible viewport area so overflowing items
|
||||
scroll inside the menu instead of letting the menu grow taller
|
||||
than the screen. */
|
||||
max-height: calc(100vh - var(--hgtHeader));
|
||||
top: var(--hgtHeader);
|
||||
width: 95%;
|
||||
z-index: 100;
|
||||
|
||||
&, ul.menu-vdi {
|
||||
list-style: none;
|
||||
padding-left: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.menu-vdi__submenu { @apply py-2 px-7 flex-col; }
|
||||
|
||||
.menu-vdi__item {
|
||||
list-style: none;
|
||||
|
||||
a, button {
|
||||
/* text */
|
||||
@apply font-bold text-20px text-white hover:underline leading-snug;
|
||||
|
||||
/* spacing & display */
|
||||
@apply block w-full p-4;
|
||||
|
||||
/* interaction */
|
||||
@apply focus-visible:bg-secondary-200 hover:bg-secondary-200;
|
||||
}
|
||||
|
||||
a { @apply block w-full; }
|
||||
|
||||
button { @apply flex w-full justify-between; }
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
@apply flex w-full justify-between;
|
||||
}
|
||||
}
|
||||
/* Show menu when toggle button is expanded */
|
||||
.nav-main__toggle[aria-expanded="true"] ~ .menu-vdi:not(.menu-vdi--sliding) { @apply !flex; /* Use !important to override hidden */ }
|
||||
}
|
||||
|
||||
/* Show menu when toggle button is expanded */
|
||||
.nav-main__toggle[aria-expanded="true"] ~ .menu-vdi:not(.menu-vdi--sliding) {
|
||||
@apply !flex; /* Use !important to override hidden */
|
||||
/* Lock the page from scrolling while the menu is open so the touch-scroll
|
||||
gesture only scrolls the menu (or doesn't scroll at all if the menu
|
||||
fits). Also stop the layout from jumping when the scrollbar disappears. */
|
||||
html:has(.nav-main__toggle[aria-expanded="true"]) body,
|
||||
body:has(.nav-main__toggle[aria-expanded="true"]) {
|
||||
overflow: hidden;
|
||||
overscroll-behavior: contain;
|
||||
touch-action: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user