Skip to content

Commit cfa5cb7

Browse files
committed
fix: adding scroll margin to prevent header being over the scrolled to content
1 parent 29158b6 commit cfa5cb7

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-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/routeMeta.ts

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

0 commit comments

Comments
 (0)