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

Ensure link to current page is visible in sidebar #2012

Closed
wants to merge 2 commits into from

Conversation

zadeviggers
Copy link

Description

When navigating sites with long sidebars (like the Astro docs), it can be quite disorientating when you click on a link and suddenly lose the context of where you are in the sidebar because it disappears. I see this behaviour in Firefox 126 and Chrome canary, so I assume it isn't just a browser quirk.

This PR solves the problem by adding a little script that is injected with the top-level sidebar. The script checks if the sidebar link to the current page is visible, and if it isn't, it is scrolled into view.

I have it set to jump instantly, but it could be jarring if the page loads really slowly. If this proves to be an issue, you could consider changing the behaviour to "smooth". This can be annoying if you see it happen on every page load though.

It seems like Vite isn't processing the script right now, which is probably because of my conditional rendering of it. I assume we want Vite to process it, but it could also be bad if it causes the JS to be loaded externally. I'd appreciate some guidance here.

Copy link

changeset-bot bot commented Jun 13, 2024

⚠️ No Changeset found

Latest commit: 384af66

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

Copy link

vercel bot commented Jun 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Jun 19, 2024 4:00pm

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Jun 13, 2024
@astrobot-houston
Copy link
Collaborator

Hello! Thank you for opening your first PR to Starlight! ✨

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel 🤩

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@delucis
Copy link
Member

delucis commented Jun 19, 2024

Thanks for the PR @zadeviggers — nice to see you again 👋

As we just chatted about on Discord, I think we’ll probably take something more like the approach in #1121, which has been a bit long running due to my own slowness getting to it, but we’ll get to eventually! Given that, we can probably close this PR.

@delucis delucis closed this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants