Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: highlight nav by default when one of the items is matched #2893

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/client/theme-default/components/VPNavBarMenuGroup.vue
Original file line number Diff line number Diff line change
@@ -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