Skip to content

useElementScrollRestoration #9573

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

Closed

Conversation

david-crespo
Copy link
Contributor

@david-crespo david-crespo commented Nov 8, 2022

First pass based on #9495. @ryanflorence will have feedback and I'm sure it'll change.

useScrollRestoration (and <ScrollRestoration />, which relies on it) only allows scroll restoration at the window level. This does not work if the scrolling container is something other than the full page, e.g., a 2x2 grid layout where the bottom right cell is the scrolling content pane. This change preserves the current API and behavior of useScrollRestoration while adding a new hook useElementScrollRestoration, which allows the caller to specify the ID of the scrolling container to use instead of window.

@changeset-bot
Copy link

changeset-bot bot commented Nov 8, 2022

⚠️ No Changeset found

Latest commit: aa03990

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@david-crespo david-crespo changed the base branch from main to dev November 8, 2022 19:32
@david-crespo david-crespo force-pushed the useElementScrollRestoration branch from dbd781f to e097850 Compare November 8, 2022 19:32
// window has scrollY but normal elements have scrollTop
const getScrollY = () => {
const el = getScrollElement();
return el ? el.scrollY || el.scrollTop : undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't typecheck. I'm sure Ryan wanted to do this differently anyway, this was just how I did it in my patch.

@brophdawg11
Copy link
Contributor

@david-crespo Thank you for putting this together! I've been trying to do some housekeeping on the repo to start off 2023 and now that we've finished the "6.4 into Remix" work and things have settled down a bit. I'm going to close this PR until the linked discussion comes around and we can re-open when needed.

joshkel added a commit to joshkel/react-router that referenced this pull request May 9, 2023
joshkel added a commit to joshkel/react-router that referenced this pull request May 9, 2023
joshkel added a commit to joshkel/react-router that referenced this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants