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

Adapt predictive search layout to new api #2192

Merged
merged 15 commits into from
Jan 12, 2023

Conversation

FCalabria
Copy link
Contributor

@FCalabria FCalabria commented Jan 4, 2023

PR Summary:

Update the predictive search component to take advantage of the new default values in the API and support all resource types

⚠️ Feature requires a flag on the shop to actually return query suggestions. This won't be available publicly for some time; and public docs will be updated once this is available.

Why are these changes introduced?

https://github.com/Shopify/discovery/issues/6681

New default values on resource[types] https://github.com/Shopify/discovery/issues/6617

What approach did you take?

The two column structure has been done with flex, using the flex-direction property to change between the mobile and desktop structure, with the appropiate changes in flex-grow for the children to fill the space when needed.

The trickiest part is the "Pages" section, that is placed in a different column depending on the screen size. I solved this duplicating the html, adding some conditional classes to the wrapper and using them with media queries to hide the page section that was not needed.

Very simplified, the final html structure looks like this
<div id="predictive-search-results">
  <div class="predictive-search__results-groups-wrapper"> <!-- This div gets conditional .predictive-search__results-groups-wrapper--no-products and .predictive-search__results-groups-wrapper--no-suggestions -->
    <div class="predictive-search__result-group"> <!-- This div is not present if it has no content (it could be present but with hidden pages on mobile) -->
      <div> <!-- Not present if it has no content -->
        <h2 id="predictive-search-queries" class="predictive-search__heading">
          Suggestions
        </h2>
        <ul
          id="predictive-search-results-queries-list"
          class="predictive-search__results-list"
        >
          <li class="predictive-search__list-item" aria-selected="false">
            <a class="predictive-search__item"> </a>
          </li>
        </ul>
      </div>
      <div class="predictive-search__pages-wrapper"> <!-- Not present if it has no content (it could be present but with hidden pages on mobile)-->
        <h2 id="predictive-search-pages" class="predictive-search__heading">
          Pages
        </h2>
        <!-- Similar ul > li, changing the ids -->
      </div>
    </div>
    <div class="predictive-search__result-group"> <!-- This div is not present if it has no content (it could be present but with hidden pages on desktop) -->
      <div> <!-- Not present if it has no content -->
        <h2 id="predictive-search-products" class="predictive-search__heading">
          Products
        </h2>
        <!-- Similar ul > li, changing the ids -->
      </div>
      <div class="predictive-search__pages-wrapper"> <!-- Not present if it has no content (it could be present but with hidden pages on desktop)-->
        <h2 id="predictive-search-pages" class="predictive-search__heading">
          Pages
        </h2>
        <!-- Similar ul > li, changing the ids -->
      </div>
    </div>
  </div>
  <div class="predictive-search__loading-state" aria-hidden="true"></div> <!-- Loading spinner -->

  <div id="predictive-search-option-search-keywords">
    <button class="predictive-search__item predictive-search__item--term">
      Search for “c”
    </button>
  </div>
</div>

Visual impact on existing themes

Users will start to get more type of results on the predictive search. They will also see the max number of results increased to 10

Testing steps/scenarios

Figma for reference

  • The predictive search dropdown can show all possible resource types (even the ones that are not queried by default)
  • The predictive search dropdown looks as expected even when some of the resource types are not populated
  • The predictive search dropdown is still accessible

Demo links

Checklist

Support all resource types
@FCalabria FCalabria requested a review from NathanPJF January 4, 2023 19:48
Copy link
Contributor

@NathanPJF NathanPJF left a comment

Choose a reason for hiding this comment

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

Requesting changes for the aria-hidden text.

FYI: I made a codepen where I used grid-template-area to manage the display in order to avoid duplicating the HTML. However, I realized it would make the JS a lot more complicated because the order of the DOM nodes couldn't be relied upon to match the visual order. Similar to focus order issues with Grid talked about here on MDN. So ultimately I think the repeated HTML is fine here.

@FCalabria FCalabria requested a review from kmeleta January 5, 2023 15:00
@FCalabria FCalabria force-pushed the new-predictive-search-api-adaptation branch from 41cbcca to 4a5f90d Compare January 5, 2023 17:30
@FCalabria FCalabria requested a review from NathanPJF January 5, 2023 17:33
display: flex;
flex-direction: column;
flex: 1 1 auto;
gap: 3rem;
Copy link
Contributor

@melissaperreault melissaperreault Jan 5, 2023

Choose a reason for hiding this comment

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

Suggested change
gap: 3rem;
gap: 2rem;

I find the 3rem gap to be very large. Suggesting 2rem to balance white space. Thoughts @al-mcquiston ? (Visual reference at 2rem for desktop, this is on Mobile)

Choose a reason for hiding this comment

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

@melissaperreault totally agree. myself and @FCalabria chatted about this and this should be updated to your suggestion

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.

Thank you Paqui! I took a quick look and will continue tomorrow! Only feedback would be about not being convinced we need 3 times the loading spinner as the query is typed. @al-mcquiston

NathanPJF
NathanPJF previously approved these changes Jan 5, 2023
Copy link
Contributor

@NathanPJF NathanPJF left a comment

Choose a reason for hiding this comment

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

Nit about the use of h3 for the list options. These can be safely changed to p tags as the .h5 class overwrites all the styling.

Tested on VoiceOver in Mobile Safari, Safari, and Chrome. And JAWS in Edge. The arrow keys navigation isn't picked up in Safari unfortunately, but I can walkthrough the page correctly with a virtual cursor (hence the addition of an aria-label on the queries list)

Comment on lines 100 to 101
<h3 class="predictive-search__item-heading h5">{{ product.title }}
</h3>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<h3 class="predictive-search__item-heading h5">{{ product.title }}
</h3>
<p class="predictive-search__item-heading h5">{{ product.title }}</p>

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't say I disagree with this suggestion, but just FYI it looks like during a11y review of the original implementation of predictive search it was specifically recommended that these product titles use h3. Though I could maybe see that being more relevant if the vendor or price is also showing. If we're confident about this change though, feel free.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for pointing that out. I read the past PR; the comment about using an h2 here made sense to me; but I don't understand why an h3 was recommended. These node don't have any child content - so I don't see it as a "heading" for any section. @svinkle : do you recall why you recommended an h3 in this past commit?

Given we're using listbox and identifying group roles, I don't believe we need this h3 to communicate structure. https://www.w3.org/WAI/ARIA/apg/example-index/listbox/listbox-grouped.html. However, I don't think h3 was communicating structure in the last PR either because the heading was put on the lowest text node in the list 🤔

Copy link
Member

Choose a reason for hiding this comment

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

do you recall why you recommended an h3 in this past commit?

I do not. As mentioned, the heading structure is not conveyed here. Swap for a generic container.

@NathanPJF
Copy link
Contributor

NathanPJF commented Jan 5, 2023

@melissaperreault you wrote

not being convinced we need 3 times the loading spinner as the query is typed

I had noticed the pattern for loading is a bit strange as well. Though something to note is that there isn't always 3 loaders. The number of loaders depends on how many resource headings (suggestions, pages, products) were on the page before the next search.

📹 In this video, I slow down the network connection, and the following can be seen:

  • I type "L" and there is a loader just in the middle of the page. I get results for both suggestions and products
  • I type "Z" and now there are 2 loaders... but I only get products back
  • I type "V", I only get 1 loader, but then 3 resource types back (suggestions, pages, products)

The loading indication could be changed. This approach may have made sense when 'Products' was the only possible heading you'd see, but now the number of resource types you get back is dynamic. Perhaps the loaders next to the resources headings should be removed completely - so no indication that anything is happening, the next content will just pop into existence.


Related, but separate issue to this PR: there's a larger issue with how loading is already being done IMO. The contents of the listbox aren't cleared between searches. This makes sense for as you're typing, but not so much when the search box is emptied; as a result, you will briefly see the results of the previous search when you start a new search. Video example where I show typing "V", clearing results, then type "T". I see the results for "V" as my new results are being loaded. This issue exists in the search box that's in production.

@bakura10
Copy link

bakura10 commented Jan 6, 2023

Maestrooo developers here. Just found this. Do you have any documentation? As this feature may have visual implication on our themes I would like to start working on this as soon as possible. I have tried to add a new "query" resource type but I have a 422 error.

As always, we would appreciate if we (theme dev) could be also added in the loop for important upgrades like this, it would also eventually allow us to provide feedback.

@translation-platform
Copy link
Contributor

translation-platform bot commented Jan 9, 2023

We have received a translation request but there is a question blocking translation work. Your help is needed.

Please answer the following questions.

Warning
Replies in GitHub are not visible to translators. Use the provided "Answer here" links. 🙅‍♀️


Note
Not your issue? Forward it to someone with more context; please don't leave it pending. 🙏
Questions? Hop in the #help-i18n-and-translation Slack channel.

@FCalabria
Copy link
Contributor Author

Related, but separate issue to this PR: there's a larger issue with how loading is already being done IMO. The contents of the listbox aren't cleared between searches. This makes sense for as you're typing, but not so much when the search box is emptied; as a result, you will briefly see the results of the previous search when you start a new search. Video example where I show typing "V", clearing results, then type "T". I see the results for "V" as my new results are being loaded. This issue exists in the search box that's in production.

@NathanPJF I have created this issue to fix this problem later, since it is a current bug and not caused by my changes. Take a look in case you want to suggest any changes.

About the loading, I talked with @al-mcquiston and we decided to remove the loading icons on the headers, since that seem to be a common pattern in other websites.

Copy link
Contributor

@kmeleta kmeleta 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 still doing some testing (a11y in particular) but overall I think this is looking good. I'm raising a couple UX questions and some code formatting stuff, but I haven't come across anything too alarming or blocking yet.

.predictive-search__heading {
border-bottom: 0.1rem solid rgba(var(--color-foreground), 0.08);
border-bottom: 0.1rem solid rgba(var(--color-foreground), 0.2);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like for this use case we typically use 0.08, though I do see a couple instances of 0.2 in the cart. Will let @melissaperreault's weigh in though if this the added opacity is warranted. (note there's an additional instance of this value above around line 27.

Not necessary to add here, but Dawn should probably already have this sort of value as a global var to ensure consistency..

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 The opacity should not change here and remain at 0.08.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the borders are extending to the left of the headings now. I don't believe I've see any discussion about this here or in the figma so I assume it's unintentional.

Choose a reason for hiding this comment

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

@melissaperreault "we lost the type specific dividers here" I had just noticed this too! Definitely want to get this reverted back.

Updating opacity to 0.08 sounds good to me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Regression fixed in latest commit

@carolinjahn
Copy link

@bakura10 the API changes are not yet ready for consumption. Theme developer comms should be going out soon (1-2 weeks) with more information ahead of the launch. If you have any specific feedback, feel free to DM me on partner slack.

@FCalabria FCalabria force-pushed the new-predictive-search-api-adaptation branch from 4e7922a to 80b0b2b Compare January 10, 2023 10:08
@FCalabria FCalabria force-pushed the new-predictive-search-api-adaptation branch from 80b0b2b to 7b6609d Compare January 10, 2023 10:09
@melissaperreault
Copy link
Contributor

Adding last piece of observations!

Transition

*This feedback is not launch blocking but something I'd like us to improve.

Perhaps the loaders next to the resources headings should be removed completely - so no indication that anything is happening, the next content will just pop into existence.

Yeah, this is the first impression that I would hope we could spend more time in a follow up task to improve the perceived performance. I am going to throw a few buzz word with hope that it helps convey in which direction we can explore: it could be smoother, snappier; buyers don't need to hold on their toes to only find out there is none of X result type. I am not sure what is the common pattern but I think we can explore further.

Would a fade in animation instead help? Is 3 relevant because things are very likely to load at different times? Could customers have the perception that things all load together, all load separate, populates as it loads (e.g. skeleton)
. I just wonder if we can build an opinion of what is the most ideal experience for the buyers.

About the loading, I talked with @al-mcquiston and we decided to remove the loading icons on the headers, since that seem to be a common pattern in other websites

We need to keep at least 1 spinner though. This will help the customer waiting as they type their query on slower connection to not be holding their breath with an empty screen.

.predictive-search__heading {
border-bottom: 0.1rem solid rgba(var(--color-foreground), 0.08);
border-bottom: 0.1rem solid rgba(var(--color-foreground), 0.2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the borders are extending to the left of the headings now. I don't believe I've see any discussion about this here or in the figma so I assume it's unintentional.

@@ -20,7 +20,7 @@

.template-search__search {
Copy link
Contributor

Choose a reason for hiding this comment

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

Group headings are centered on the search page.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed by moving the center class off the container to the heading.

@al-mcquiston al-mcquiston reopened this Jan 10, 2023
@Shopify Shopify deleted a comment from al-mcquiston Jan 11, 2023
@@ -15,7 +15,7 @@
{%- if predictive_search.resources.queries.size > 0 or predictive_search.resources.collections.size > 0 -%}
<div>
<h2 id="predictive-search-queries" class="predictive-search__heading text-body caption-with-letter-spacing">
{{ 'templates.search.suggestions' | t }}
{{- 'templates.search.suggestions' | t -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

While reviewing the output, I noticed that the whitespaces were being rendered in the inspector. This doesn't have an impact on the UI really, but it makes the output more inline with what we want.

Copy link
Contributor

@NathanPJF NathanPJF left a comment

Choose a reason for hiding this comment

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

My comments about the output in VoiceOver and JAWS have been addressed, and the feature works as expected. Nice work @FCalabria !

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.

Thank you! Looks good to me!

Tiny detail for when we tackle loading states, we need to consider this use case too for when no results are found and are only left with the CTA. (video example)

Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

Approved. Overall, the feature works well and I see no real issues with the implementation 👍 Nice work!

I do find the Voiceover experience in safari a little unfortunate in that arrow key navigation doesn't provide much [if any] feedback, nor does it announce the results live region updates. However, the markup here looks to spec (announcements in JAWS work well) and these VO issues seem to be preexisting in dawn, so I can't really consider these issues to be blocking.

Given the increased complexity in the search results with this change though, I do think it would be nice if you could timebox a follow-up to see if we can make any improvements here at all. I believe there is also some ongoing UX discussion around loading states and we would appreciate any effort to come to a solution in a follow-up as well. Let me know if we can help with any of this.

@NathanPJF NathanPJF merged commit 2f41ad3 into main Jan 12, 2023
@NathanPJF NathanPJF deleted the new-predictive-search-api-adaptation branch January 12, 2023 16:57
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Adapt predictive search layout to new api

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Co-authored-by: Nathan Ferguson <nathan.pj.ferguson@gmail.com>
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.

8 participants