docusaurus-lunr-search icon indicating copy to clipboard operation
docusaurus-lunr-search copied to clipboard

Search text not removed - when click the result which already an active url

Open Nilanth opened this issue 4 years ago • 7 comments

Hi, The search text in the search bar is not removed once we click the search result.

Nilanth avatar Jun 15 '20 06:06 Nilanth

Thanks for reporting @Nilanth, I will take a look :+1:

lelouch77 avatar Jun 15 '20 07:06 lelouch77

This issue happens only when you select a result which is already an active URL..

lelouch77 avatar Jul 04 '20 11:07 lelouch77

No, it occurs on all pages! You can check in this demo itself https://lelouch77.github.io/docusaurus-lunr-search-demo/

Nilanth avatar Jul 04 '20 12:07 Nilanth

When moving from landing page to documentation the search is cleared. However @Nilanth is right that once in the documentation, the search is never cleared.

mattcorner avatar Sep 04 '20 07:09 mattcorner

Thats the old documentation link.. try this https://lelouch77.github.io/docusaurus-lunr-search-multilang @Nilanth @mattcorner

lelouch77 avatar Sep 04 '20 07:09 lelouch77

Its a bit inconsistent. Sometimes it does remove clear the search, but a lot of the time it doesn't. Here it is not clearing on the new demo @lelouch77

This only occurs for doc to doc navigation

docs-lunr-search-not-clearing

mattcorner avatar Sep 04 '20 07:09 mattcorner

Hi, The search text in the search bar is not removed once we click the search result.

On /src/theme/SearchBar/index.js, I added _input.setVal('') and _event.target.blur() on the handleSelected function (line 25):

const initAlgolia = (searchDocs, searchIndex, DocSearch) => {
  new DocSearch({
    searchDocs,
    searchIndex,
    inputSelector: "#search_input_react",
    handleSelected: (_input, _event, suggestion) => {
      const url = baseUrl + suggestion.url;
      const a = document.createElement("a");
      a.href = url;

      _input.setVal(''); // clear value
      _event.target.blur(); // remove focus

      history.push(url);
    }
  });
};

So the input is cleared and its focus is removed when a result is clicked. Hope it helps!

felipeog avatar Jan 24 '21 07:01 felipeog

fixed in new version 3.2.0

praveenn77 avatar Oct 16 '23 02:10 praveenn77