Skip to content

Commit 1f5e625

Browse files
fix: hard-code scroll margin per-page to account for fixed header size (#1504)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 61f8df6 commit 1f5e625

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ definePageMeta({
1313
'/package/code/:packageName/v/:version/:filePath(.*)?',
1414
// '/code/@:org?/:packageName/v/:version/:filePath(.*)?',
1515
],
16+
scrollMargin: 160,
1617
})
1718
1819
const route = useRoute('code')

app/pages/package-docs/[...path].vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ definePageMeta({
77
name: 'docs',
88
path: '/package-docs/:path+',
99
alias: ['/package/docs/:path+', '/docs/:path+'],
10+
scrollMargin: 180,
1011
})
1112
1213
const route = useRoute('docs')

app/pages/package/[[org]]/[name]/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// stub page to help with paths
33
definePageMeta({
44
name: 'package',
5+
scrollMargin: 150,
56
})
67
</script>
78

app/router.options.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import type { RouterConfig } from 'nuxt/schema'
33
export default {
44
scrollBehavior(to, _from, savedPosition) {
55
// If the browser has a saved position (e.g. back/forward navigation), restore it
6+
67
if (savedPosition) {
78
return savedPosition
89
}
9-
1010
// If navigating to a hash anchor, scroll to it
1111
if (to.hash) {
12-
return { el: to.hash, behavior: 'smooth' }
12+
const { scrollMargin } = to.meta
13+
return {
14+
el: to.hash,
15+
behavior: 'smooth',
16+
top: typeof scrollMargin == 'number' ? scrollMargin : 70,
17+
}
1318
}
1419

1520
// Otherwise, scroll to the top of the page

app/types/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
import '#app'
2+
import '#vue-router'
13
export * from './icon'
24
export * from './navigation'
5+
6+
declare module '#app' {
7+
interface PageMeta {
8+
/**
9+
* top margin in pixels for scrolling to an element
10+
* @default 70
11+
*/
12+
scrollMargin?: number
13+
}
14+
}

0 commit comments

Comments
 (0)