Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Facet filters] Remove animation from product grid re render #2597

Merged
merged 5 commits into from
May 2, 2023

Conversation

ludoboludo
Copy link
Contributor

PR Summary:

This PR explores what we could do to limit the amount of animation when using facet filters and re rendering the product grid.
We're not applying the animation on product cards that are coming up above the fold. But are on the rest of them when scrolled into view.

Why are these changes introduced?

Fixes #2578

What approach did you take?

  • I added a class scroll-trigger--facet-cancel on each grid__item from the facets.js file, when we're re rendering the elements.
  • Added some CSS styling to cancel the animation and set the opacity to 1 when the class mentioned above is applied.
  • In the animation.js Im removing the class in question if it's not within the viewport.

Other considerations

Visual impact on existing themes

Testing steps/scenarios

  • Step 1

Demo links

Checklist

@ludoboludo ludoboludo requested a review from kjellr May 1, 2023 18:31
Copy link
Contributor

@kjellr kjellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! This eliminates the unnecessarily repetitive behavior that existed before when the animation would re-render, and still retains the ability to have items animate in on scroll. Nice work!

@ludoboludo ludoboludo requested a review from LucasLacerdaUX May 1, 2023 19:02
@melissaperreault melissaperreault self-requested a review May 1, 2023 19:37
Copy link
Contributor

@melissaperreault melissaperreault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉 🚢

@kjellr kjellr requested a review from stufreen May 2, 2023 12:29
Copy link
Contributor

@stufreen stufreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works. The only downside is that it adds some facet-specific logic to animations.js. I'm not sure the logic would be obvious to someone looking at the code with no context.

Did you consider removing the SCROLL_ANIMATION_TRIGGER_CLASS instead, after the section rendering API query? So in facets.js you could change to something like:

static renderProductGridContainer(html) {
    const productGridHtml = new DOMParser().parseFromString(html, 'text/html');
    const scrollTriggerEls = Array.from(productGridHtml.getElementsByClassName('scroll-trigger'));
    scrollTriggerEls.forEach((el) => el.classList.remove('scroll-trigger'));
    document.getElementById('ProductGridContainer').innerHTML =
      productGridHtml.getElementById('ProductGridContainer').innerHTML;
  }

I tested that quickly but not extensively. Let me know which one you prefer and I can approve it.

@ludoboludo
Copy link
Contributor Author

Yeah I have the same downside with the approach I have. Though it seem to be the one that make the most sense.
At least if we're wanting to animate in all the product cards that aren't shown in the viewport when it's been re rendered.

Otherwise we could just not animate any of the cards being re rendered 🤷

Your example is what I had originally 👍

Curious to hear Lucas' take on it.

Copy link
Contributor

@stufreen stufreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it's better to keep the animation for offscreen elements 👍

Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this approach to cancel animations, I'm just not sure if we should name it after facets when it has nothing facet-specific. It's our only use case so far, but the code itself is just toggling a class that allows animation to be cancelled :P

@ludoboludo ludoboludo merged commit e263e89 into main May 2, 2023
@ludoboludo ludoboludo deleted the filter-animation-fix branch May 2, 2023 16:37
jabrms pushed a commit to fp-trading/fp-trading-theme that referenced this pull request Jun 6, 2023
jabrms pushed a commit to fp-trading/fp-trading-theme that referenced this pull request Jun 12, 2023
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Animations] Disable slide-in animation when filters are changed
5 participants