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

fix: toc does not highlight clicked anchor + use scroll-margin-top #5425

Merged
merged 4 commits into from
Aug 26, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Aug 26, 2021

Motivation

The issue can simply be seen by clicking here: https://docusaurus.io/docs#docsify

Despite #docsify being the anchor, the toc highlights GitBook:

image

This is because we apply a top offset when computing the active anchors, but this offset only makes sense when the navbar is sticky.

We now compute that offset according to how the navbar sticky/hideable config.

Also refactors the workaround to make clicked anchors appear under the sticky navbar, because a css property exists for that (scroll-margin-top, see https://twitter.com/JoshWComeau/status/1332015868725891076) and is quite well supported. If we encounter issues we'll revert.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

This now works: https://deploy-preview-5425--docusaurus-2.netlify.app/docs/#docsify

preview + local tests on Chrome/Safari/FF with/without sticky navbar

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Aug 26, 2021
@slorber slorber requested a review from lex111 as a code owner August 26, 2021 14:03
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 26, 2021
@netlify
Copy link

netlify bot commented Aug 26, 2021

✔️ [V2]

🔨 Explore the source changes: 410a933

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6127a8da16f26a0008270df8

😎 Browse the preview: https://deploy-preview-5425--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Aug 26, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 91
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5425--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Aug 26, 2021

Size Change: +1.03 kB (0%)

Total Size: 815 kB

Filename Size Change
website/build/assets/css/styles.********.css 95 kB +78 B (0%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 66.2 kB +204 B (0%)
website/build/docs/index.html 43.6 kB +476 B (+1%)
website/build/docs/installation/index.html 50.9 kB +271 B (+1%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 36.2 kB
website/build/assets/js/main.********.js 410 kB
website/build/blog/index.html 36.9 kB
website/build/index.html 29.8 kB
website/build/tests/docs/index.html 24.1 kB
website/build/tests/docs/standalone/index.html 21.9 kB

compressed-size-action

@slorber slorber merged commit 2a72c64 into main Aug 26, 2021
@slorber slorber deleted the slorber/fix-toc-highlighting-offset branch August 26, 2021 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants