-
Notifications
You must be signed in to change notification settings - Fork 157
Pagination allows clicking on next & last buttons when there are no results #785
Comments
I've done some digging and it seems like the issue is in the pagination connector in Both the next & last buttons check the vue-instantsearch/src/components/Pagination.vue Lines 116 to 129 in 4f8eb4b
vue-instantsearch/src/components/Pagination.vue Lines 146 to 159 in 4f8eb4b
(Github is not showing me a snippet here, so I'm doing it by hand) renderFn(
{
createURL: this.createURL(state),
currentRefinement: page,
refine: this.refine,
nbHits: results.nbHits,
nbPages,
pages: pager.pages(),
isFirstPage: pager.isFirstPage(),
isLastPage: pager.isLastPage(),
widgetParams,
instantSearchInstance,
},
false
); It's value comes from the paginator class. I think that this is where the bug is: (Github is not showing me a snippet here, so I'm doing it by hand) isLastPage() {
return this.currentPage === this.total - 1;
} When there are no results, the current page is 0 === 0 - 1 which is always false. Should I have opened an issue in |
Thanks for your thorough look into this! You've indeed seemed to identify what's going on, if you want to make a pull request here that would be appreciated. Note that Vue InstantSearch (for now) is using InstantSearch v3 (not yet v4, latest) |
I've made a pull request to InstantSearch.js (v4 first) with your suggestion: algolia/instantsearch#4422 thanks a lot! I'll also follow it up with a PR for v3 so we can have this fixed in Vue InstantSearch too. |
* fix(pagination): isLastPage when there's no pages fixes algolia/vue-instantsearch#785 * fix logic & add test * update usage to show isLastPage now works correctly co-authored-by: dotboris@users.noreply.github.com
Bug 🐞
What is the current behavior?
When you have a search with no results, the pagination will render in a way where the next & last buttons are clickable. This doesn't make much sense since there's no second page when there are no results.
Make a sandbox with the current behavior
Instead of creating a sandbox, I've managed to reproduce this on the live demo (storybook) from the documentation.
somethingthatwillnevermatch
in the search barYou'll notice that the pagination is rendered as if I can click to go to the next / last page. The buttons are clickable but they do nothing.
What is the expected behavior?
I expect the pagination to either vanish or render in a completely disabled state where the next & previous buttons look like they're disabled.
Note that the
instantsearch.js
lib seems to handle this gracefully as it hides the pagination when there are no results. Here's the e-commerce example handling this edge case: https://instantsearchjs.netlify.app/examples/e-commerce/search/?query=somethingthatwillnotmatchforsureDoes this happen only in specific situations?
Only when there are no search results.
What is the proposed solution?
Either the show the buttons as disabled or hide the whole thing.
What is the version you are using?
The text was updated successfully, but these errors were encountered: