When implementing code for initial empty query, search breaks on single char queries
See original GitHub issueDo you want to request a feature or report a bug? Bug. I’m not certain if this is related to my implementation or if I have uncovered a bug in instant search.
Bug: What is the current behavior? I’ve implemented the “initial empty query” behaviour that was discussed in this ticket #4 where the user can have no results when the page is first loaded. I’m using the following code to do that:
var search = instantsearch({
searchFunction: function(helper) {
if (helper.state.query === "") {
return;
}
helper.search();
}
});
search.addWidget(
instantsearch.widgets.searchbox({
queryHook: function(query, search) {
if (query === "") {
search();
} else {
search(query);
}
}
})
);
View my example here: https://codepen.io/Giovanni-Mattucci/pen/zwRrGo
Do the following steps:
- Search for “nursing”
- Remove your search term
- Type a single letter Notice that the search doesn’t happen.
Bug: What is the expected behavior? That after clearing search, searching by a single letter works.
Bug: What browsers are impacted? Which versions? All browsers.
What is the version you are using? Always use the latest one before opening a bug issue. Instantsearch.js 1.11.13
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Ahh, so there is an additional step of hiding the hits area! Ok good to know. Thanks for the help, I think I got it figured out 😃
Oh ok then that something that you can do. When you catch that the query is empty then you can hide the part that display the results and the filters and when it’s not empty you display them back.
To go even further, you can use the event render on instantsearch.js to change what is displayed in a smoother way. You can find of fork of your example on codepen. I mainly changed the searchFunction: