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

Search bar does not update with "no results found" when using external filtering #849

Closed
ad9242 opened this issue Jun 29, 2023 · 0 comments
Assignees
Labels
search-bar component The generic component, includes both the web component and the React component
Milestone

Comments

@ad9242
Copy link
Contributor

ad9242 commented Jun 29, 2023

Summary of the bug

When using external filtering with ic-search-bar, the suggestions do not update with "No results found" when passing an empty array as the options prop, if there have previously been options supplied. This is causing a problem on the guidance site.

🪜 How to reproduce

Using the following code:

  1. type ca into the search bar - suggestions will be shown
  2. now type "z" to make text "caz", it still shows the previous suggestion options

🧐 Expected behaviour

The search bar should display "No results found" when given an empty array as options.

📸 Screenshots or code

<ic-search-bar  label="Search for coffee" placeholder="Type to search" debounce="300" disable-filter="true" id="external-filter-search"
  ></ic-search-bar>
  <br />
  <ic-typography
    >Suggested search options: Espresso, Double Espresso, Flat White,
    Cappuccino, Americano, Mocha</ic-typography
  >
  <br />
  <ic-typography
    >The IcChange event will trigger 300ms after you finish typing. 1
    second later, the options in the searchbar menu will be
    updated.</ic-typography
  >
  <script>
    var mockData = [
      { label: "Espresso", value: "espresso" },
      { label: "Double Espresso", value: "doubleespresso" },
      { label: "Flat White", value: "flatwhite" },
      { label: "Cappuccino", value: "cappucino" },
      { label: "Americano", value: "americano" },
      { label: "Mocha", value: "mocha" },
    ];
    var select = document.querySelector("#external-filter-search");
    var optionSelected = false;
    function handleFilter(event) {
      query = event.detail.value;
      if (query !== optionSelected) {
        if (query.length > 0) {
          mockAPI = (query) => {
            filteredResults = mockData.filter((m) =>
              m.label.toLowerCase().includes(query.toLowerCase())
            );
            return new Promise((resolve) =>
              setTimeout(
                () => resolve(filteredResults),
                event.type === "icChange" ? 2000 : 1000
              )
            );
          };
          mockAPI(query).then((results) => (select.options = results));
        } else {
          select.options = [];
        }
      }
      optionSelected = "";
    }
    function handleSelect(event) {
      optionSelected = true;
    }
    select.addEventListener("icOptionSelect", handleSelect);
    select.addEventListener("icChange", handleFilter);
    select.addEventListener("icRetryLoad", handleFilter);
  </script>

Additional info

Think this may have been introduced and is masked by the loading state work. Seems to be related to the preLoad variable being true which is preventing the no results text being set.

We should maybe add a story into storybook without the loading state but with external filtering

@ad9242 ad9242 added the search-bar component The generic component, includes both the web component and the React component label Jun 29, 2023
@ad9242 ad9242 added this to the V2.x milestone Jun 29, 2023
@GCHQ-Developer-530 GCHQ-Developer-530 self-assigned this Jul 11, 2023
GCHQ-Developer-530 added a commit that referenced this issue Jul 12, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 12, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 12, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 13, 2023
…ound state

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 13, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 13, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 13, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 13, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 20, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
GCHQ-Developer-530 added a commit that referenced this issue Jul 21, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
jd239 pushed a commit that referenced this issue Jul 24, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
jd239 pushed a commit that referenced this issue Jul 24, 2023
…ound

Update search bar to correctly show no results found state when external filtering is used but not
loading. Added story to show this.

. #849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
search-bar component The generic component, includes both the web component and the React component
Projects
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants