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

Scroll position doesn't maintain #37

Closed
kimmccaskill opened this issue Apr 8, 2022 · 2 comments
Closed

Scroll position doesn't maintain #37

kimmccaskill opened this issue Apr 8, 2022 · 2 comments

Comments

@kimmccaskill
Copy link

You can see here: https://codesandbox.io/s/vigilant-platform-xy6onk?file=/src/index.tsx

Expected: scroll position maintained when switching outportals
Actual: scroll position resets to top

@kimmccaskill
Copy link
Author

I've attempted to manipulate the divs DOM node with portalNode.element.scrollTop = 400; but that doesn't seem to work either

@pimterry
Copy link
Member

Unfortunately I think this is unavoidable. React-reverse-portal is just moving the DOM node in and out of the DOM, but it sounds like many browsers reset the scroll position in any case where an element leaves the DOM. I don't think there's anything we can do to work around that here I'm afraid. Even if we automatically tracked & restored the scroll position for the top-level element, this would still affect the scroll state of node nested deeply within content.

To maintain scroll state like this, you'll have to track and restore that state using React itself somewhere else.

If you do have any suggestions to fix this though, I'm all ears! PRs very welcome.

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

2 participants