Skip to content

Commit 31fc2db

Browse files
committed
Add active class in sidebar title list to "lvl0" DocSearch config
1 parent 565df84 commit 31fc2db

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/.vuepress/theme/components/TheSidebar.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<template v-for="(nav, index) in items">
2121
<span
2222
:key="`nav-heading-${index}`"
23-
class="mt-12 ml-4 text-xl font-bold sidebar__title-list bg-primary"
23+
class="mt-12 ml-4 text-xl font-bold bg-primary"
24+
:class="{ 'sidebar__title-list--active': sidebarTitleActive === nav.title }"
2425
>
2526
{{ nav.title }}
2627
</span>
@@ -88,7 +89,7 @@
8889
</template>
8990

9091
<script>
91-
import { computed } from '@vue/composition-api'
92+
import { computed, ref, watch } from '@vue/composition-api'
9293
9394
import { resolveSidebarItems } from '@/theme/utils/sidebar'
9495
@@ -97,8 +98,18 @@ export default {
9798
9899
setup (_, { root }) {
99100
const items = computed(() => resolveSidebarItems(root.$page.regularPath, root.$site, root.$themeLocaleConfig))
101+
const sidebarTitleActive = ref(null)
102+
103+
watch(() => root.$route.path, val => {
104+
const item = items.value.find(item => item.children.some(child => child.path === val))
105+
if (item) {
106+
sidebarTitleActive.value = item.title
107+
}
108+
}, { immediate: true })
109+
100110
return {
101-
items
111+
items,
112+
sidebarTitleActive
102113
}
103114
}
104115
}

0 commit comments

Comments
 (0)