Skip to content

Comments

fix: hard-code scroll margin per-page to account for fixed header size#1504

Merged
danielroe merged 4 commits intonpmx-dev:mainfrom
WilcoSp:fix/scrolling-toc
Feb 22, 2026
Merged

fix: hard-code scroll margin per-page to account for fixed header size#1504
danielroe merged 4 commits intonpmx-dev:mainfrom
WilcoSp:fix/scrolling-toc

Conversation

@WilcoSp
Copy link
Contributor

@WilcoSp WilcoSp commented Feb 14, 2026

When using table of content the scroll behaviour caused that the scrolled to element to be underneath the header(s). I've now added scroll margin to the scroll behaviour so that scrolled to element isn't any more underneath the header(s).

by default the margin is 70 but it's possible with definePageMeta to set a different scroll margin, at least right now the package, code & docs pages have different scroll margins due to their additional headers.

before:
afbeelding -> afbeelding

after:
afbeelding -> afbeelding


this will fix #1428 & fix #1518

@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 22, 2026 10:16pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 22, 2026 10:16pm
npmx-lunaria Ignored Ignored Feb 22, 2026 10:16pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This pull request introduces a scrolling offset feature to address anchor links being hidden behind sticky headers. The changes add a scrollMargin property to page metadata across multiple route files with varying offsets (150–180 pixels). The router's scroll behaviour is enhanced to read this metadata and apply the offset when scrolling to hash-based anchors. A new optional scrollMargin property is added to the PageMeta type interface with a default value of 70 pixels. The router now preserves saved scroll positions and implements smooth scrolling with the configured margins.

Possibly related PRs

Suggested reviewers

  • danielroe
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly explains the scroll margin implementation to prevent headers overlapping anchored content, detailing default and custom values.
Linked Issues check ✅ Passed The changes successfully implement scroll margin functionality to prevent anchor links from scrolling behind sticky headers, addressing issue #1428 requirements.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing scroll margin behaviour for anchor navigation, with no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/router.options.ts 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@WilcoSp WilcoSp changed the title fix: header(s) overlapping scrolled to element (toc) fix: adding scroll marging to scrollbehavior to prevent header overlapping scroll target element Feb 22, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

name: 'docs',
path: '/package-docs/:path+',
alias: ['/package/docs/:path+', '/docs/:path+'],
scrollMargin: 180,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check the actual file and verify line 10 content
cat -n app/pages/package-docs/[...path].vue | head -20

Repository: npmx-dev/npmx.dev

Length of output: 781


🏁 Script executed:

# Check router.options.ts implementation
fd 'router.options.ts' --exec cat {} \;

Repository: npmx-dev/npmx.dev

Length of output: 680


🏁 Script executed:

# Verify CSS values in the Vue component, specifically around lines 273-275
cat -n app/pages/package-docs/[...path].vue | sed -n '270,280p'

Repository: npmx-dev/npmx.dev

Length of output: 379


🏁 Script executed:

# Search for scroll-related CSS or scroll-mt values in the file
rg 'scroll-m|scroll-margin' app/pages/package-docs/[...path].vue

Repository: npmx-dev/npmx.dev

Length of output: 83


Align scrollMargin: 180 with CSS scroll-mt-32 (128 px) for consistent scroll positioning

Direct URL navigation with a hash anchor applies the CSS scroll-mt-32 rule (128 px), whereas router-driven navigation (e.g., clicking a TOC link) uses the scrollMargin: 180 offset. This 52 px difference results in inconsistent scroll positions depending on the navigation path, affecting user experience. Align both values to ensure the symbol lands at the same vertical position regardless of how the user reaches it.

@danielroe danielroe changed the title fix: adding scroll marging to scrollbehavior to prevent header overlapping scroll target element fix: hard-code scroll margin per-page to account for fixed header size Feb 22, 2026
@danielroe danielroe added this pull request to the merge queue Feb 22, 2026
Merged via the queue into npmx-dev:main with commit 1f5e625 Feb 22, 2026
18 checks passed
@github-actions
Copy link

Thanks for your first contribution, @WilcoSp! 👏

We'd love to welcome you to the npmx community. Come and say hi on Discord! And once you've joined, visit npmx.wamellow.com to claim the contributor role.

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.

Package page scrolls down when clicking side bar summary titles Scroll anchors disappear behind sticky header

2 participants