Skip to content

Commit

Permalink
Prevent auto-hide when mega menu is open
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLacerdaUX committed Mar 31, 2022
1 parent 2cf7a95 commit 775c7c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assets/component-mega-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
border-radius: 0;
border-right: 0;
left: 0;
max-height: calc(100vh - var(--header-bottom-position-desktop, 20rem) - 4rem);
overflow-y: auto;
padding-bottom: 2.4rem;
padding-top: 2.4rem;
Expand All @@ -18,6 +17,10 @@
z-index: -1;
}

.shopify-section-header-sticky .mega-menu__content {
max-height: calc(100vh - var(--header-bottom-position-desktop, 20rem) - 4rem);
}

.header-wrapper--border-bottom .mega-menu__content {
border-top: 0;
}
Expand Down
7 changes: 4 additions & 3 deletions assets/details-disclosure.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ customElements.define('details-disclosure', DetailsDisclosure);
class HeaderMenu extends DetailsDisclosure {
constructor() {
super();
this.header = document.querySelector('header');
this.header = document.querySelector('.header-wrapper');
}

onToggle() {
document.body.classList.toggle('overflow-hidden', this.querySelectorAll('.mega-menu[open]').length);
if (!this.header) return;
this.header.preventHide = !!this.querySelectorAll('.mega-menu[open]').length;

if (document.documentElement.style.getPropertyValue('--header-bottom-position-desktop') !== '') return;
if (this.header) document.documentElement.style.setProperty('--header-bottom-position-desktop', `${Math.floor(this.header.getBoundingClientRect().bottom)}px`);
document.documentElement.style.setProperty('--header-bottom-position-desktop', `${Math.floor(this.header.getBoundingClientRect().bottom)}px`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sections/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@
if (this.predictiveSearch && this.predictiveSearch.isOpen) return;

if (scrollTop > this.currentScrollTop && scrollTop > this.headerBounds.bottom) {
if (this.preventHide) return;
requestAnimationFrame(this.hide.bind(this));
} else if (scrollTop < this.currentScrollTop && scrollTop > this.headerBounds.bottom) {
if (!this.preventReveal) {
Expand All @@ -635,7 +636,6 @@
requestAnimationFrame(this.reset.bind(this));
}


this.currentScrollTop = scrollTop;
}

Expand Down

0 comments on commit 775c7c0

Please sign in to comment.