From 544c61eb0bef54d0a7ccab4d79cf09fc81ef0212 Mon Sep 17 00:00:00 2001 From: Tyler Alsbury <60230011+tyleralsbury@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:45:20 -0400 Subject: [PATCH] Fixed issues when header is hidden (#3545) * Fixed issues when header is hidden * Fixed predictive search on search page * Made it so that the drawer still shows up --- assets/cart-drawer.js | 4 ++++ assets/predictive-search.js | 2 +- layout/theme.liquid | 17 +++++++++++++++++ sections/header.liquid | 16 ++-------------- sections/predictive-search.liquid | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/assets/cart-drawer.js b/assets/cart-drawer.js index 048e43232d2..ad37f3cb871 100644 --- a/assets/cart-drawer.js +++ b/assets/cart-drawer.js @@ -9,6 +9,8 @@ class CartDrawer extends HTMLElement { setHeaderCartIconAccessibility() { const cartLink = document.querySelector('#cart-icon-bubble'); + if (!cartLink) return; + cartLink.setAttribute('role', 'button'); cartLink.setAttribute('aria-haspopup', 'dialog'); cartLink.addEventListener('click', (event) => { @@ -76,6 +78,8 @@ class CartDrawer extends HTMLElement { const sectionElement = section.selector ? document.querySelector(section.selector) : document.getElementById(section.id); + + if (!sectionElement) return; sectionElement.innerHTML = this.getSectionInnerHTML(parsedState.sections[section.id], section.selector); }); diff --git a/assets/predictive-search.js b/assets/predictive-search.js index ed33c078d81..b30210be21c 100644 --- a/assets/predictive-search.js +++ b/assets/predictive-search.js @@ -240,7 +240,7 @@ class PredictiveSearch extends SearchForm { getResultsMaxHeight() { this.resultsMaxHeight = - window.innerHeight - document.querySelector('.section-header').getBoundingClientRect().bottom; + window.innerHeight - document.querySelector('.section-header')?.getBoundingClientRect().bottom; return this.resultsMaxHeight; } diff --git a/layout/theme.liquid b/layout/theme.liquid index b4bd68d9adc..70db635823b 100644 --- a/layout/theme.liquid +++ b/layout/theme.liquid @@ -31,6 +31,10 @@ + + + + {%- if settings.animations_reveal_on_scroll -%} {%- endif -%} @@ -252,6 +256,15 @@ {% endstyle %} {{ 'base.css' | asset_url | stylesheet_tag }} + + + {%- if settings.cart_type == 'drawer' -%} + {{ 'component-cart-drawer.css' | asset_url | stylesheet_tag }} + {{ 'component-cart.css' | asset_url | stylesheet_tag }} + {{ 'component-totals.css' | asset_url | stylesheet_tag }} + {{ 'component-price.css' | asset_url | stylesheet_tag }} + {{ 'component-discounts.css' | asset_url | stylesheet_tag }} + {%- endif -%} {%- unless settings.type_body_font.system? -%} {% comment %}theme-check-disable AssetPreload{% endcomment %} @@ -355,5 +368,9 @@ {%- if settings.predictive_search_enabled -%} {%- endif -%} + + {%- if settings.cart_type == 'drawer' -%} + + {%- endif -%} diff --git a/sections/header.liquid b/sections/header.liquid index 6e0bbd7292f..45e713fb334 100644 --- a/sections/header.liquid +++ b/sections/header.liquid @@ -2,21 +2,15 @@ - + {%- if settings.predictive_search_enabled -%} {%- endif -%} + {%- if section.settings.menu_type_desktop == 'mega' -%} {%- endif -%} -{%- if settings.cart_type == "drawer" -%} - {{ 'component-cart-drawer.css' | asset_url | stylesheet_tag }} - {{ 'component-cart.css' | asset_url | stylesheet_tag }} - {{ 'component-totals.css' | asset_url | stylesheet_tag }} - {{ 'component-price.css' | asset_url | stylesheet_tag }} - {{ 'component-discounts.css' | asset_url | stylesheet_tag }} -{%- endif -%}