Add option to refresh scroll for a particular link when using morph/preserve scroll otherwise #1396
Replies: 6 comments
-
|
Can't you control this with the meta tag from the server side depending on the URL? |
Beta Was this translation helpful? Give feedback.
-
|
Do you mean modifying the meta tag from the server side when someone clicks a pagination link? We have this set up roughly using turbo-rails gem (using Stimulus to submit the form automatically when filters are selected): This works really well in that scroll is preserved when the user selects different filters. However, when they click a pagination link, we'd like to remove the scroll preservation. If we modify the meta tag when a pagination link is clicked, then we would have the opposite problem that then the filters wouldn't have scroll preserve. Or am I misunderstanding your suggestion? If we don't use |
Beta Was this translation helpful? Give feedback.
-
|
You can change the value of the meta tag dynamically when you want the scroll to be preserved. For example, you could add a parameter to the filters form that indicates that the request is coming from that form, and if so, you make the scroll preserved using the meta tag. |
Beta Was this translation helpful? Give feedback.
-
|
Ah yeah, I see, that works, and is probably nicer than my convoluted JS override. Though it would be nice to have a solution that doesn't involve passing a parameter through the URL. |
Beta Was this translation helpful? Give feedback.
-
|
We don't plan to increase the scope of the API yet, but I understand the use case, so I'll leave it open for now! |
Beta Was this translation helpful? Give feedback.
-
|
Great, thank you! I ended up using the View: Stimulus controller: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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:
I tried removing the scroll preserve directive from the meta tag, and adding
data-turbo-refresh-scroll='preserve'to the form, anddata-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-scrollattribute 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.Beta Was this translation helpful? Give feedback.
All reactions