Skip to content

Commit

Permalink
feat: highlight nav by default when one of the items is matched (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanryuu committed Sep 10, 2023
1 parent cb49673 commit b1fbece
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/client/theme-default/components/VPNavBarMenuGroup.vue
@@ -1,14 +1,29 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { computed } from 'vue'
import { useData } from '../composables/data'
import { isActive } from '../../shared'
import VPFlyout from './VPFlyout.vue'
defineProps<{
const props = defineProps<{
item: DefaultTheme.NavItemWithChildren
}>()
const { page } = useData()
const isChildActive = (navItem: DefaultTheme.NavItem) => {
if ('link' in navItem) {
return isActive(
page.value.relativePath,
navItem.link,
!!props.item.activeMatch
)
} else {
return navItem.items.some(isChildActive)
}
}
const childrenActive = computed(() => isChildActive(props.item))
</script>

<template>
Expand All @@ -19,7 +34,7 @@ const { page } = useData()
page.relativePath,
item.activeMatch,
!!item.activeMatch
)
) || childrenActive
}"
:button="item.text"
:items="item.items"
Expand Down

0 comments on commit b1fbece

Please sign in to comment.