Skip to content

Add search facet filtering#566

Merged
KaichenWang merged 28 commits intomainfrom
add-search-facet-filtering
Sep 15, 2021
Merged

Add search facet filtering#566
KaichenWang merged 28 commits intomainfrom
add-search-facet-filtering

Conversation

@KaichenWang
Copy link
Contributor

@KaichenWang KaichenWang commented Sep 3, 2021

Why are these changes introduced?

Fixes #46
Fixes #538

What approach did you take?

  • Modularize facets:

    • Move facets markup into snippets/facets.liquid
    • Move CSS into assets/component-facets.css
    • Rename JS to assets/facets.js
    • Rename variables to disassociate with collection
    • Move locales strings from section.collection_template to products.facets
    • Update references
  • Render facets snippet in main-collection-product-grid.liquid and main-search.liquid

  • Add facet section settings in main-search and pass to snippet

  • Add additional Liquid logic to handle empty search results (differentiate scenarios that can lead to no search results - see "Other considerations" for more info)

Other considerations

Notes on differentiating 2 different empty states to present the buyer with context-aware messaging/UI:

Scenarios

  1. No results due to no term matches - i.e. the search term is misspelled (example: “shooes”)
  2. No results due to filtering specificity - i.e. the search term is correct and there are 5 matches (example: “shoes”), but a price filter is out of range for all 5 matches

Liquid

  1. If no results and filters is an empty drop: there were no results for the query
  2. If no results and filters is NOT an empty drop, it means the filters led to no results

Demo links

Checklist

Additional

  • Regression test filtering/sorting on Collection pages

@@ -1,25 +1,29 @@
{{ 'template-collection.css' | asset_url | stylesheet_tag }}
{{ 'component-card.css' | asset_url | stylesheet_tag }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diff best viewed with Hide whitespace changes enabled

@KaichenWang
Copy link
Contributor Author

KaichenWang commented Sep 3, 2021

@tyleralsbury requested review from you because you have the most context on facet filtering on themes side.

@carolineschnapp requested review from you because you have context on how to best leverage search.filters Liquid object; in particular for scenarios where no results are returned. The logic is implemented in sections/main-search.liquid.

Thank you

@tyleralsbury
Copy link
Contributor

Super, Kai. Thanks for creating this. I'll probably get a chance to take a look at it next week. I'll carve out some time in my calendar to take a good look. Very exciting to get this into Search! 🚀

@ghost
Copy link

ghost commented Sep 6, 2021

When changing sort on search page the number of results increases. Ex: https://os2-demo.myshopify.com/search?q=art

@KaichenWang
Copy link
Contributor Author

@grumpyoldflo

When changing sort on search page the number of results increases. Ex: https://os2-demo.myshopify.com/search?q=art

Hi, the increase in result count here isn't actually due to sorting. On Dawn, we set search prefix option value to last (more info here). So if you conduct a search using the search box, the url will typically look something like this /search?q=art&options%5Bprefix%5D=last, but if you manually input a url without the &options%5Bprefix%5D=last part (which sorting will automatically append), the results count will differ.

@ludoboludo ludoboludo self-requested a review September 7, 2021 15:09
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Working well, didn't run into any issues.

A few things I noted:

  • when clicking on the Skip to main content link, it messes with the loading state of the page/filters. But doesn't seem to do it on the collection page. video
  • a few accessibility things. We don't announce the details being open when using voice over and pressing Enter. Seem to work with the spacebar. Also the link from the bubbles to remove the filter aren't being announced as something to remove the filter in question. But those aren't related to this PR. (video)

@KaichenWang
Copy link
Contributor Author

@ludoboludo Thanks for reviewing.

when clicking on the Skip to main content link, it messes with the loading state of the page/filters. But doesn't seem to do it on the collection page.

Good catch. This also brought to my attention that the function which runs on window history change onHistoryChange runs twice, because the custom HTML element <facet-filters-form> is defined twice on the page (mobile and desktop). This needs to be addressed. I will therefore close the PR for now and work on fixing this first.

@KaichenWang KaichenWang closed this Sep 7, 2021
@KaichenWang KaichenWang reopened this Sep 8, 2021
@KaichenWang
Copy link
Contributor Author

KaichenWang commented Sep 8, 2021

Reopening the PR after updating some facets.js methods to static. The fetching, caching and rendering of the product grid is functionality that is now handled by the FacetFiltersForm class itself and doesn't need to be replicated across instances of FacetFiltersForm. This also resolves the issue with onHistoryChange event being triggered twice, since the event listener is now being defined in a static method.

assets/facets.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah shoot I think we can't use this yet as it's not supported on previous version of Safari when we're supposed to support the last 2 versions:

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't re test the rest of the functionality as I think we won't be able to use that approach 🙁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good point. I will look into an alternative

Copy link
Contributor Author

@KaichenWang KaichenWang Sep 9, 2021

Choose a reason for hiding this comment

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

In my testing, it appears static methods work fine even on iOS 13, but static class properties were causing a JS error. I've therefore moved the properties out of the class. 88b35d1

@KaichenWang KaichenWang closed this Sep 9, 2021
@KaichenWang KaichenWang reopened this Sep 9, 2021
…h-facet-filtering

# Conflicts:
#	sections/main-search.liquid
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Left some small comments but overall didn't encounter any issues, seem to work well 👌

ludoboludo
ludoboludo previously approved these changes Sep 13, 2021
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

<span class="active-facets__button-inner button button--tertiary">
{{ value.label | escape }}
{% render 'icon-close-small' %}
<span class="visually-hidden">{{ 'products.facets.clear_filter' | t }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it easier to put it at the end so it doesn't disrupt the selectors to style label before it ? I feel like it sounds better when hearing: Clear filter Buttermilk. Rather than Buttermilk Clear filter.
But I don't have strong feelings, this is much better already.

Copy link
Contributor Author

@KaichenWang KaichenWang Sep 14, 2021

Choose a reason for hiding this comment

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

I deemed the value.label to be the most pertinent information and that it should be read first by the screenreader. Otherwise, quickly tabbing through the list of filters, the screenreader will repeatedly announce "Clear filter" and the user must pause and wait for each value.label to be read.

tyleralsbury
tyleralsbury previously approved these changes Sep 14, 2021
Copy link
Contributor

@tyleralsbury tyleralsbury left a comment

Choose a reason for hiding this comment

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

This is looking really great overall. I focused on looking at the changes to the JS and the use of the Snippet. I think this is a good case for Snippet use and you used it in a really smart way. Though we are trying to avoid using snippets, this is a pretty large piece of complex code that would be a pain to maintain if it were duplicated between two different files, so I do agree with the snippet use here.

Aside from that, I like the efficient data sharing between instances of the classes. I think it's really a smart way to handle that and is something we should consider when building out these types of components.

I tested on desktop and mobile on Chrome and Firefox and it all worked well. I played around with it for about 10 - 15 minutes and didn't run into any issues. I also tried using keyboard navigation and using my mouse and both worked well, too. Overall, I think it's looking good.

Code and Testing both look good to me 👍 Nothing to flag in particular.

Also great collaboration between yourself and Ludo in the comments. I was able to follow along with everything you two discussed and get all the context I needed. Very helpful!

ludoboludo
ludoboludo previously approved these changes Sep 15, 2021
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

Looks like all translations came back 👌

tyleralsbury
tyleralsbury previously approved these changes Sep 15, 2021
Copy link
Contributor

@tyleralsbury tyleralsbury left a comment

Choose a reason for hiding this comment

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

Took a quick look at the translation commits and they look 👍

@shopify shopify bot dismissed stale reviews from tyleralsbury and ludoboludo via be5d512 September 15, 2021 20:01
@KaichenWang KaichenWang merged commit afbf8c5 into main Sep 15, 2021
@KaichenWang KaichenWang deleted the add-search-facet-filtering branch September 15, 2021 21:18
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
* Move facet/filtering to snippet, include snippet in collection and search

* Update logic for empty states

* Update facet variables names

* Generalize naming to disassociate elements from collection

* Disassociate strings from collection

* Update JS naming for facets

* Update 19 translation files

* Update 10 translation files

* Change facet functions to static

* Ensure title links inherit parent font-size

* Simplify naming to follow BEM conventions

* Update container id

* Load facet js conditionally when enabled

* Update from Shopify for theme dawn/add-search-facet-filtering

* Revert "Update from Shopify for theme dawn/add-search-facet-filtering"

This reverts commit 3793c14.

* Refactor event listener

* Move static properties out of class

* Address PR feedback

* Update 17 translation files

* Update 13 translation files

* Update from Shopify for theme dawn/add-search-facet-filtering

* Revert "Update from Shopify for theme dawn/add-search-facet-filtering"

This reverts commit be5d512.

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Co-authored-by: shopify-online-store[bot] <79544226+shopify-online-store[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mobile view uses "Filter and sort" wording when filters are disabled Search Results Template: Facet Filtering

3 participants

Comments