Instantsearch.js: Question on "infiniteHits" widget

Created on 27 Aug 2020  路  2Comments  路  Source: algolia/instantsearch.js

Hi!

Recently noticed that clicking load more button on infiniteHits widget forces window to jump/scroll to the bottom. I don't recall this behavior previously as well as I did not updated instantSearch for some time.

So the question is - is it a default behavior? Meaning previously I had something on my site preventing it from jumping to the bottom on load more click?

Or it's not a default behavior, meaning I broke up it somehow?

Cheers and thank you!

Most helpful comment

Hi @fujiii, this is a bug / change in behaviour in chrome we also track in https://github.com/algolia/react-instantsearch/issues/2966

You can update to InstantSearch.css v7.4.3 with the following workaround (which you can also add without updating):

// Prevent InfiniteHits buttons from moving scroll position
 // https://bugs.chromium.org/p/chromium/issues/detail?id=1110323
 .ais-InfiniteHits-loadPrevious,
 .ais-InfiniteHits-loadMore {
   overflow-anchor: none;
 }

All 2 comments

Hi @fujiii, this is a bug / change in behaviour in chrome we also track in https://github.com/algolia/react-instantsearch/issues/2966

You can update to InstantSearch.css v7.4.3 with the following workaround (which you can also add without updating):

// Prevent InfiniteHits buttons from moving scroll position
 // https://bugs.chromium.org/p/chromium/issues/detail?id=1110323
 .ais-InfiniteHits-loadPrevious,
 .ais-InfiniteHits-loadMore {
   overflow-anchor: none;
 }

@Haroenv,

thank you for explanation and more elegant solution, because I had to solve it like this:

$('body').on('click', '.ais-infinite-hits--showmoreButton',
function() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
window.onscroll = function() {
window.scrollTo(0, scrollTop);
window.onscroll = function() {};
};
});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spone picture Spone  路  3Comments

samouss picture samouss  路  3Comments

ChristopherDosin picture ChristopherDosin  路  4Comments

timkelty picture timkelty  路  3Comments

anthonyBertrant picture anthonyBertrant  路  3Comments