Skip to content

Commit b1fbece

Browse files
authoredSep 10, 2023
feat: highlight nav by default when one of the items is matched (#2893)
1 parent cb49673 commit b1fbece

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎src/client/theme-default/components/VPNavBarMenuGroup.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
<script lang="ts" setup>
22
import type { DefaultTheme } from 'vitepress/theme'
3+
import { computed } from 'vue'
34
import { useData } from '../composables/data'
45
import { isActive } from '../../shared'
56
import VPFlyout from './VPFlyout.vue'
67
7-
defineProps<{
8+
const props = defineProps<{
89
item: DefaultTheme.NavItemWithChildren
910
}>()
1011
1112
const { page } = useData()
13+
14+
const isChildActive = (navItem: DefaultTheme.NavItem) => {
15+
if ('link' in navItem) {
16+
return isActive(
17+
page.value.relativePath,
18+
navItem.link,
19+
!!props.item.activeMatch
20+
)
21+
} else {
22+
return navItem.items.some(isChildActive)
23+
}
24+
}
25+
26+
const childrenActive = computed(() => isChildActive(props.item))
1227
</script>
1328

1429
<template>
@@ -19,7 +34,7 @@ const { page } = useData()
1934
page.relativePath,
2035
item.activeMatch,
2136
!!item.activeMatch
22-
)
37+
) || childrenActive
2338
}"
2439
:button="item.text"
2540
:items="item.items"

0 commit comments

Comments
 (0)