Skip to content
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

Preserve Scroll Position through history from React Router #146

Open
miswartz opened this issue Apr 19, 2017 · 6 comments
Open

Preserve Scroll Position through history from React Router #146

miswartz opened this issue Apr 19, 2017 · 6 comments

Comments

@miswartz
Copy link

The default scroll bars preserve scroll position when going back and forward through history with react router historys goBack calls.

For example if I'm on a list of all products page, and I scroll half way down, and I click in to a product page, and then hit back, the previous scroll position is preserved and used. I go back to the product list half way down.

This does not happen with this these custom scrollbars and I would like it to. Any ideas?

@cdtinney
Copy link

cdtinney commented May 30, 2017

There's a closed issue for this over at react-router-scroll - Using react-router-scroll with react-custom-scrollbars #42

One solution (from what I understand) would be modifications to scroll-behavior to support providing custom scrolling behavior via props, overriding the default scrollLeft and scrollTop with those of react-custom-scrollbars.

@cdtinney
Copy link

For reference, I've implemented this via the API and Redux.

First, add a ref attribute to the Scrollbars component and a callback for onScrollStop. When the onScrollStop handler is called, use this._scrollbarsRef.getScrollTop() to get the Y co-ordinate. A Redux action is dispatched that stores the scroll top for that view.

When the component is mounted again, the value from the store is used to call scrollTop() to set the scroll position.

@diegogurgel
Copy link

diegogurgel commented Jan 20, 2019

@cdtinney I'm trying to do that but the scrollTop() keep calling onScrollStop again causing infinite renders. @malte-wessel Is it possible to add something like scrollTop(100 , cancelEvent)?

@camdagr8
Copy link

@cdtinney I have the same setup but see a flash from the scrollTop 0 to the saved position. How did you deal with that?

@cdtinney
Copy link

cdtinney commented Apr 26, 2019 via email

@ChristopherHButler
Copy link

@cdtinney do you have a working codepen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants