-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to refresh scroll for a particular link when using morph/preserve scroll otherwise #1350
Comments
Can't you control this with the meta tag from the server side depending on the URL? |
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 |
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. |
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. |
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! |
Great, thank you! I ended up using the View:
Stimulus controller:
|
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-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.The text was updated successfully, but these errors were encountered: