Description
We are using Turbo refresh with morph and scroll preserve with turbo action "replace" on an index view page that allows filtering and search. It works really well, except that we have some pagination links at the bottom of the page that we would like to drop the scroll preserve, so that the scroll moves up to the top of the search results instead of staying at the bottom of the page. Is this possible? Google's AI helpfully(?) told me:
Yes, with Turbo (a JavaScript framework for fast web interactions), you can configure individual links to either "reset" or "preserve" the scroll position when navigating, meaning some links can jump to the top of the page while others maintain the current scroll position upon clicking, using the data-turbo-refresh-scroll attribute with values "reset" or "preserve" respectively.
Key points about using data-turbo-refresh-scroll:
How to implement: Add the data-turbo-refresh-scroll attribute directly to the anchor tag () with either "preserve" to maintain the scroll position or "reset" (default) to jump to the top on navigation.
I tried removing the scroll preserve directive from the meta tag, and adding data-turbo-refresh-scroll='preserve'
to the form, and data-turbo-refresh-scroll='reset'
to the pagination links, but this did not work and I could not find any solution otherwise.
I ended up adding some custom JavaScript with a data-turbo-refresh-scroll
attribute in a similar vein to #37 (comment), but it is a little convoluted since we are trying to scroll to an anchor. It would be great if we could just add an attribute to the link to drop the scroll preserve.
Activity