Repository navigation
fix(client): honor scroll-margin-top when scrolling to hash - #1724
Open
Mister-Hope wants to merge 1 commit into
Open
Mister-Hope wants to merge 1 commit into
Mister-Hope wants to merge 1 commit into
Conversation
Coverage Report for CI Build 36333404826Coverage remained the same at 73.948%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hash navigation ignores
scroll-margin-top, so themes cannot keep anchor targets clear of a fixed navbar with it.The router scrolls with
{ el: to.hash }, andvue-routerresolves that element itself (elRect.top - docRect.top+window.scrollTo) instead of usingscrollIntoView, soscroll-margin-top/scroll-padding-tophave no effect. Themes are left with a negativemargin-toppaired with a matchingpadding-top, which shifts the box (including its padding) above the element and makes the content above it unclickable.Changes
packages/client: scroll hash targets withscrollIntoViewand returnfalse, soscroll-margin-topis honored.getElementByIdis used instead ofquerySelector, as an id may contain characters that are invalid in a CSS selector (e.g. the space in#foo baror the:in#foo:1).Tests
Added
e2e/tests/router/scroll-to-hash.spec.tswith two pages whose targets havescroll-margin-top: 100px, covering:#target:1),All 5 fail without the change (the target ends up at the top of the viewport, or the page does not scroll at all) and pass with it.
Verification
pnpm lint,pnpm check-types,pnpm test:unit(666 tests) pass.pnpm e2e:dev(86 tests) andpnpm e2e:build(93 tests) pass.