Skip to content

Commit

Permalink
feat: 导航栏子元素高亮时父元素高亮
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Dec 22, 2023
1 parent 387dff9 commit 1b7d3da
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/theme/src/client/components/Nav/NavBarMenuGroup.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<script lang="ts" setup>
import { usePageData } from '@vuepress/client'
import type { NavItemWithChildren } from '../../../shared/index.js'
import { computed } from 'vue'
import type { NavItem, NavItemWithChildren } from '../../../shared/index.js'
import { isActive } from '../../utils/index.js'
import Flyout from '../Flyout/index.vue'
defineProps<{
const props = defineProps<{
item: NavItemWithChildren
}>()
const page = usePageData()
const isChildActive = (navItem: NavItem) => {
if ('link' in navItem) {
return isActive(
page.value.path,
navItem.link,
!!props.item.activeMatch
)
} else {
return navItem.items.some(isChildActive)
}
}
const childrenActive = computed(() => isChildActive(props.item))
</script>

<template>
<Flyout
:class="{
'navbar-menu-group': true,
'active': isActive(page.path, item.activeMatch, !!item.activeMatch),
'active': isActive(page.path, item.activeMatch, !!item.activeMatch) || childrenActive,
}"
:button="item.text"
:items="item.items"
Expand Down

0 comments on commit 1b7d3da

Please sign in to comment.