Skip to content

Commit

Permalink
fix: click on heading and toc (#671)
Browse files Browse the repository at this point in the history
Co-authored-by: Yaël Guilloux <[email protected]>
  • Loading branch information
bdrtsky and Tahul authored Nov 17, 2022
1 parent e356d02 commit dbdffc8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
15 changes: 15 additions & 0 deletions app/router.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { RouterConfig } from '@nuxt/schema'
// https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig> {
scrollBehavior (to, from, savedPosition) {
if (to.hash) {
const { marginTop } = getComputedStyle((document.querySelector(to.hash) as any))
const marginTopValue = parseInt(marginTop)
const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
return {
top: offset,
behavior: 'smooth'
}
}
}
}
7 changes: 0 additions & 7 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
box-shadow: none !important;
}

html,
body {
height: 100%;
width: 100%;
overflow: auto;
}

body {
overflow-y: scroll;
-webkit-font-smoothing: antialiased;
Expand Down
11 changes: 1 addition & 10 deletions components/docs/DocsPageContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ onBeforeUnmount(() => {
<DocsPrevNext />
</template>
</article>

<!-- TOC -->
<div
v-if="hasToc"
:class="{
'closed': !isOpen,
}"
class="toc"
>
<div class="toc-wrapper">
Expand Down Expand Up @@ -217,13 +215,6 @@ css({
alignSelf: 'flex-start',
py: '{space.8}',
},
'&.closed': {
display: 'flex',
alignItems: 'center',
'@mq.lg': {
display: 'block'
}
},
'.toc-wrapper': {
width: '100%',
backdropFilter: '{backdrop.filter}',
Expand Down
34 changes: 13 additions & 21 deletions components/docs/DocsTocLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,18 @@ const router = useRouter()
const { activeHeadings, updateHeadings } = useScrollspy()
watch(
() => route.path,
() => {
if (process.client) {
setTimeout(() => {
updateHeadings([
...document.querySelectorAll('.document-driven-page h1, .docus-content h1'),
...document.querySelectorAll('.document-driven-page h2, .docus-content h2'),
...document.querySelectorAll('.document-driven-page h3, .docus-content h3'),
...document.querySelectorAll('.document-driven-page h4, .docus-content h4')
])
}, 300)
}
},
{
immediate: true
}
)
if (process.client) {
setTimeout(() => {
updateHeadings([
...document.querySelectorAll('.document-driven-page h1, .docus-content h1'),
...document.querySelectorAll('.document-driven-page h2, .docus-content h2'),
...document.querySelectorAll('.document-driven-page h3, .docus-content h3'),
...document.querySelectorAll('.document-driven-page h4, .docus-content h4')
])
}, 300)
}
const scrollToHeading = (id: string) => {
function scrollToHeading (id: string) {
router.push(`#${id}`)
emit('move', id)
}
Expand Down Expand Up @@ -78,11 +70,11 @@ css({
'@mq.lg': {
paddingRight: '{space.3}'
},
'&:hover': {
'&:not(.active):hover': {
color: '{colors.gray.900}',
},
'@dark': {
'&:hover': {
'&:not(.active):hover': {
color: '{colors.gray.400}',
},
},
Expand Down

1 comment on commit dbdffc8

@vercel
Copy link

@vercel vercel bot commented on dbdffc8 Nov 17, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.