Skip to content

Commit

Permalink
Fixed issues when header is hidden (#3545)
Browse files Browse the repository at this point in the history
* Fixed issues when header is hidden

* Fixed predictive search on search page

* Made it so that the drawer still shows up
  • Loading branch information
tyleralsbury committed Jul 15, 2024
1 parent 8071714 commit 544c61e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 4 additions & 0 deletions assets/cart-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion assets/predictive-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<script src="{{ 'constants.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'pubsub.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'global.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-disclosure.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-modal.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'search-form.js' | asset_url }}" defer="defer"></script>

{%- if settings.animations_reveal_on_scroll -%}
<script src="{{ 'animations.js' | asset_url }}" defer="defer"></script>
{%- endif -%}
Expand Down Expand Up @@ -252,6 +256,15 @@
{% endstyle %}

{{ 'base.css' | asset_url | stylesheet_tag }}
<link rel="stylesheet" href="{{ 'component-cart-items.css' | asset_url }}" media="print" onload="this.media='all'">

{%- 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 %}
Expand Down Expand Up @@ -355,5 +368,9 @@
{%- if settings.predictive_search_enabled -%}
<script src="{{ 'predictive-search.js' | asset_url }}" defer="defer"></script>
{%- endif -%}

{%- if settings.cart_type == 'drawer' -%}
<script src="{{ 'cart-drawer.js' | asset_url }}" defer="defer"></script>
{%- endif -%}
</body>
</html>
16 changes: 2 additions & 14 deletions sections/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
<link rel="stylesheet" href="{{ 'component-search.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-menu-drawer.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-cart-notification.css' | asset_url }}" media="print" onload="this.media='all'">
<link rel="stylesheet" href="{{ 'component-cart-items.css' | asset_url }}" media="print" onload="this.media='all'">

{%- if settings.predictive_search_enabled -%}
<link rel="stylesheet" href="{{ 'component-price.css' | asset_url }}" media="print" onload="this.media='all'">
{%- endif -%}

{%- if section.settings.menu_type_desktop == 'mega' -%}
<link rel="stylesheet" href="{{ 'component-mega-menu.css' | asset_url }}" media="print" onload="this.media='all'">
{%- 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 -%}

<style>
header-drawer {
Expand Down Expand Up @@ -102,13 +96,7 @@
}
{%- endstyle -%}

<script src="{{ 'details-disclosure.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'details-modal.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'cart-notification.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'search-form.js' | asset_url }}" defer="defer"></script>
{%- if settings.cart_type == "drawer" -%}
<script src="{{ 'cart-drawer.js' | asset_url }}" defer="defer"></script>
{%- endif -%}

<svg xmlns="http://www.w3.org/2000/svg" class="hidden">
<symbol id="icon-search" viewbox="0 0 18 19" fill="none">
Expand Down
2 changes: 1 addition & 1 deletion sections/predictive-search.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<img
class="predictive-search__image"
src="{{ product.featured_media | image_url: width: 150 }}"
alt="{{ product.featured_media.alt }}"
alt="{{ product.featured_media.alt | escape }}"
width="50"
height="{{ 50 | divided_by: product.featured_media.preview_image.aspect_ratio }}"
>

Check warning on line 151 in sections/predictive-search.liquid

View workflow job for this annotation

GitHub Actions / Theme Check Report

sections/predictive-search.liquid#L145-L151

[ImgLazyLoading] Use loading="eager" for images visible in the viewport on load and loading="lazy" for others
Expand Down

0 comments on commit 544c61e

Please sign in to comment.