Skip to content

Commit

Permalink
feat(theme): auto open collapsed sidebar on entering (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
licitdev committed Aug 1, 2022
1 parent f9d2799 commit f4f1a6c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client/theme-default/components/VPSidebarGroup.vue
@@ -1,6 +1,8 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { ref, watchEffect } from 'vue'
import { useData } from 'vitepress'
import { isActive } from '../support/utils'
import VPIconPlusSquare from './icons/VPIconPlusSquare.vue'
import VPIconMinusSquare from './icons/VPIconMinusSquare.vue'
import VPSidebarLink from './VPSidebarLink.vue'
Expand All @@ -17,6 +19,13 @@ watchEffect(() => {
collapsed.value = !!(props.collapsible && props.collapsed)
})
const { page } = useData()
watchEffect(() => {
if(props.items.some((item) => { return isActive(page.value.relativePath, item.link) })){
collapsed.value = false
}
})
function toggle() {
if (props.collapsible) {
collapsed.value = !collapsed.value
Expand Down

0 comments on commit f4f1a6c

Please sign in to comment.