Skip to content

Commit

Permalink
Using font size and spacing for mega menu hierarchy (Shopify#1520)
Browse files Browse the repository at this point in the history
* Using font size and spacing for mega menu hierarchy

Co-authored-by: LucasLacerdaUX <lucas.lacerda@shopify.com>
Co-authored-by: Lucas Lacerda <37168033+LucasLacerdaUX@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 4, 2022
1 parent 8b9b54f commit 1576ad0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
30 changes: 18 additions & 12 deletions 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 All @@ -28,15 +31,8 @@
}

.mega-menu[open] .mega-menu__content {
animation: animateMenuOpen var(--duration-default) ease;
animation-fill-mode: forwards;
}

@media (prefers-reduced-motion) {
.mega-menu[open] .mega-menu__content {
opacity: 1;
transform: translateY(0);
}
opacity: 1;
transform: translateY(0);
}

.mega-menu__list {
Expand All @@ -49,11 +45,21 @@
.mega-menu__link {
color: rgba(var(--color-foreground), 0.75);
display: block;
font-size: 1.3rem;
line-height: calc(1 + 0.3 / var(--font-body-scale));
padding-bottom: 0.8rem;
padding-top: 0.8rem;
padding-bottom: 0.6rem;
padding-top: 0.6rem;
text-decoration: none;
transition: text-decoration var(--duration-short) ease;
word-wrap: break-word;
}

.mega-menu__link--level-2 {
font-size: 1.4rem;
}

.mega-menu__link--level-2:not(:only-child) {
margin-bottom: 0.8rem;
}

.header--top-center .mega-menu__list {
Expand Down
1 change: 1 addition & 0 deletions assets/component-menu-drawer.css
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ details[open].menu-opening > .menu-drawer__submenu {
background-color: transparent;
font-family: var(--font-body-family);
font-style: var(--font-body-style);
text-align: left;
}

.no-js .menu-drawer__close-button {
Expand Down
7 changes: 5 additions & 2 deletions assets/details-disclosure.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +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() {
if (!this.header) return;
this.header.preventHide = this.mainDetailsToggle.open;

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
4 changes: 2 additions & 2 deletions sections/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
<ul class="mega-menu__list page-width{% if link.levels == 1 %} mega-menu__list--condensed{% endif %}" role="list">
{%- for childlink in link.links -%}
<li>
<a href="{{ childlink.url }}" class="mega-menu__link link font-body-bold{% if childlink.current %} mega-menu__link--active{% endif %}"{% if childlink.current %} aria-current="page"{% endif %}>
<a href="{{ childlink.url }}" class="mega-menu__link mega-menu__link--level-2 link{% if childlink.current %} mega-menu__link--active{% endif %}"{% if childlink.current %} aria-current="page"{% endif %}>
{{ childlink.title | escape }}
</a>
{%- if childlink.links != blank -%}
Expand Down 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 1576ad0

Please sign in to comment.