Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

@shopify/theme-predictive-search-component #96

Merged
merged 1 commit into from
Oct 11, 2019

Conversation

antoinegrant
Copy link
Member

@antoinegrant antoinegrant commented Apr 24, 2019

Description

A component that controls the state of a predictive search UI.

Reviews

Reviewers should focus on this commit as this is a branch of predictive-search.

Example

const predictivesearch = new PredictiveSearch({
  selectors: {
    input: '[data-predictive-search-input="header"]',
    reset: '[data-predictive-search-reset="header"]',
    result: '[data-predictive-search-result="header"]'
  },
  resultTemplateFct: data => {
    return `
      <div class="predictive-search">
        <ul class="predictive-search__list">
          ${products.map(
            product => `
            <li>
              <img src="${product.image}" alt="${product.title}" />
              <span>${produtc.title}</span>
            </li>
          `
          )}
        </ul>
      </div>
    `;
  },
  onInputFocus: nodes => {
    // You can get a reference to active target
    console.log(nodes.input.id); //-> input
    console.log(nodes.submit.id); //-> submit
    console.log(nodes.result.id); //-> result
  },
  onInputKeyup: nodes => {
    return true; // This will allow the event callback to execute
  },
  onInputBlur: nodes => {
    return false; // This will prevent the event callback to execute
  },
  onInputClear: nodes => {},
  onBeforeKill: nodes => {},
  onBeforeOpen: nodes => {},
  onOpen: nodes => {},
  onBeforeClose: nodes => {},
  onClose: nodes => {},
  onDestroy: nodes => {}
});

// Public methods
predictivesearch.open();
predictivesearch.close();
predictivesearch.destroy();

CC @NathanPJF @t-kelly @beefchimi

@antoinegrant antoinegrant force-pushed the predictive-search-component branch from 41f0951 to 334182f Compare April 29, 2019 02:43
@antoinegrant antoinegrant force-pushed the predictive-search branch 4 times, most recently from 442fda7 to 4ef0863 Compare April 29, 2019 19:17
@antoinegrant antoinegrant force-pushed the predictive-search-component branch 2 times, most recently from da5eadc to 8c3bab9 Compare April 29, 2019 19:26
const predictivesearch = new PredictiveSearch({
selectors: {
input: '[data-predictive-search-input="header"]',
reset: '[data-predictive-search-reset="header"]',
Copy link
Member Author

Choose a reason for hiding this comment

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

The logic for a reset button is not completely fleshed out atm.

Choose a reason for hiding this comment

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

I will remove this line.

Choose a reason for hiding this comment

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

Can we delete line 11 then?

```js
const predictivesearch = new PredictiveSearch({
selectors: {
input: '[data-predictive-search-input="header"]',
Copy link
Contributor

Choose a reason for hiding this comment

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

Show somewhere that these are required

selectors: {
input: '[data-predictive-search-input="header"]',
reset: '[data-predictive-search-reset="header"]',
result: '[data-predictive-search-result="header"]'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these selectors have assumptions that each is only returning 1 DOM element?

console.log(nodes.input.id); //-> input
console.log(nodes.submit.id); //-> submit
console.log(nodes.result.id); //-> result
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this confusing: Does this callback only fires when the input is focused? or does it callback when either input, submit, or result focuses?

What is the purpose to have this event proxy if it's only giving a callback on input focus? Could these be solved by simply having a bindEvent callback so that theme developers can do whatever they need to do, be it focus, keyup, blur, touch, ... etc browser events?

onBeforeOpen: nodes => {},
onOpen: nodes => {},
onBeforeClose: nodes => {},
onClose: nodes => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

are these for animation events?

@antoinegrant antoinegrant force-pushed the predictive-search-component branch from 8c3bab9 to d67c4d0 Compare May 15, 2019 18:37
@antoinegrant antoinegrant changed the base branch from predictive-search to master August 2, 2019 17:48
@rickitan rickitan force-pushed the predictive-search-component branch 2 times, most recently from a0ab60b to a51a98b Compare August 9, 2019 18:39
@antoinegrant
Copy link
Member Author

Please feel free to reach out if needed to ship this PR! 🙂

@carolineschnapp
Copy link

@antoinegrant A lot of questions and comments have not been addressed on the PR and, although the code here in this PR is used in Debut, and will ship with it within days, there seems to be mistrust in the work here. Also, the Predictive Search API has changed, this PR reflects the changes, and what is on master does not. Either we merge this PR without addressing requested changes, or we create a new PR that just removes the component entirely because what we have on master is misleading. What do you think I should do?

@BrendaSegalShopify
Copy link

BrendaSegalShopify commented Oct 10, 2019

@chrisberthe @t-kelly my understanding is that there might be some opposition to making this script public. Is this the case? We wanted to use this library to ship the new version of Debut with Predictive Search and to eventually spread it to other themes.

@antoinegrant antoinegrant mentioned this pull request Oct 10, 2019
@chrisberthe
Copy link
Contributor

my understanding is that there might be some opposition to making this script public. Is this the case?

Pretty sure there isn't any opposition on our side - where did you hear this? Plus, the script is technically already public.

@BrendaSegalShopify
Copy link

Thanks @chrisberthe, good to know. I think I misunderstood.
I'm glad there isn't any opposition to making this public 👍

@antoinegrant antoinegrant force-pushed the predictive-search-component branch 3 times, most recently from b7ab286 to ee723ca Compare October 10, 2019 21:56
@antoinegrant antoinegrant force-pushed the predictive-search-component branch 4 times, most recently from 538cfef to 91108ef Compare October 11, 2019 00:55
@antoinegrant antoinegrant force-pushed the predictive-search-component branch from 91108ef to 93b0e2a Compare October 11, 2019 01:17
Copy link

@BrendaSegalShopify BrendaSegalShopify left a comment

Choose a reason for hiding this comment

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

Although I can't comment from a coding perspective, I 🎩 and it's working great.

Thanks so much for all your help in getting this out the door! 🥇

@antoinegrant antoinegrant merged commit a5cda02 into master Oct 11, 2019
@antoinegrant antoinegrant deleted the predictive-search-component branch October 11, 2019 14:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants