Skip to content

Auto-scroll on page load for internal page links #504

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

Merged
merged 1 commit into from
May 7, 2025

Conversation

plocket
Copy link
Collaborator

@plocket plocket commented Feb 27, 2025

Would love an eye on this. If you refresh a page with a hash in the url there's a little visual jump that I don't like, but it may be worth it.

@plocket plocket requested a review from samglover February 27, 2025 18:55
@samglover
Copy link
Contributor

samglover commented Feb 28, 2025

I loaded the branch locally but I'm not sure I'm seeing what I'm supposed to. If I click an anchor link (for example, http://localhost:3000/docs/components/ALKiln/security#alkiln_role), it moves instantly to the anchor location. Seems normal, although I think the reason to use scrollIntoView() is usually to add a smooth animated transition.

But on reloading, if I reload in Chrome I end up back at the top of the page. I only return to the anchor if I put the cursor in the address bar and hit enter. I don't see any visual jump. In Firefox I only end up back at the top of the page if I use a cache-clearing reload. Otherwise I stay put. In Safari, weirdly, the anchor does not work at all.

I tried the same thing on the LIT Lab website (https://suffolklitlab.org/events/lit-con/#agenda) and got different behavior. Reloading the page with or without cache-clearing did not return me to the top of the page on any browser.

@plocket
Copy link
Collaborator Author

plocket commented Apr 15, 2025

I believe you, but I can't replicate your behavior. If you have time at some point, I'd love to pair and experiment with what you see. Either way, is this an improvement over what we have now?

Regarding a smooth transition - scrollIntoView() can create a smooth animation, but it doesn't have to. It can just jump to a part of the page. I get motion sick from that kind of smoothing animation and haven't done research about browser settings I could use to counteract this behavior, so I tend to avoid adding those kinds of animations.

Copy link
Contributor

@samglover samglover left a comment

Choose a reason for hiding this comment

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

As I said in my comment, I don't think I'm seeing the intended behavior, but if @plocket is satisfied it's A-OK with me!

@nonprofittechy nonprofittechy merged commit eabe116 into main May 7, 2025
2 checks passed
@nonprofittechy nonprofittechy deleted the alkiln_anchors branch May 7, 2025 21:51
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

Successfully merging this pull request may close these issues.

3 participants