fix(theme): navbar menu group is incorrectly highlighted (#5113)

---------

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/5118/head
WizardsBowl 7 months ago committed by GitHub
parent 2e36f5c312
commit b28667b6b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,14 @@ const href = computed(() =>
: props.item.link : props.item.link
) )
const isActiveLink = computed(() =>
isActive(
page.value.relativePath,
props.item.activeMatch || href.value,
!!props.item.activeMatch
)
)
defineOptions({ inheritAttrs: false }) defineOptions({ inheritAttrs: false })
</script> </script>
@ -25,13 +33,7 @@ defineOptions({ inheritAttrs: false })
<div class="VPMenuLink"> <div class="VPMenuLink">
<VPLink <VPLink
v-bind="$attrs" v-bind="$attrs"
:class="{ :class="{ active: isActiveLink }"
active: isActive(
page.relativePath,
item.activeMatch || href,
!!item.activeMatch
)
}"
:href :href
:target="item.target" :target="item.target"
:rel="props.rel ?? item.rel" :rel="props.rel ?? item.rel"

@ -11,31 +11,36 @@ const props = defineProps<{
const { page } = useData() const { page } = useData()
const isChildActive = (navItem: DefaultTheme.NavItem) => { const isActiveGroup = computed(() => {
if (props.item.activeMatch) {
return isActive(page.value.relativePath, props.item.activeMatch, true)
}
return isChildActive(props.item)
})
function isChildActive(navItem: DefaultTheme.NavItem): boolean {
if ('component' in navItem) return false if ('component' in navItem) return false
if ('link' in navItem) { if ('link' in navItem) {
const href =
typeof navItem.link === 'function'
? navItem.link(page.value)
: navItem.link
return isActive( return isActive(
page.value.relativePath, page.value.relativePath,
typeof navItem.link === "function" ? navItem.link(page.value) : navItem.link, navItem.activeMatch || href,
!!props.item.activeMatch !!navItem.activeMatch
) )
} }
return navItem.items.some(isChildActive) return navItem.items.some(isChildActive)
} }
const childrenActive = computed(() => isChildActive(props.item))
</script> </script>
<template> <template>
<VPFlyout <VPFlyout
:class="{ :class="{ VPNavBarMenuGroup: true, active: isActiveGroup }"
VPNavBarMenuGroup: true,
active:
isActive(page.relativePath, item.activeMatch, !!item.activeMatch) ||
childrenActive
}"
:button="item.text" :button="item.text"
:items="item.items" :items="item.items"
/> />

@ -16,18 +16,19 @@ const href = computed(() =>
? props.item.link(page.value) ? props.item.link(page.value)
: props.item.link : props.item.link
) )
const isActiveLink = computed(() =>
isActive(
page.value.relativePath,
props.item.activeMatch || href.value,
!!props.item.activeMatch
)
)
</script> </script>
<template> <template>
<VPLink <VPLink
:class="{ :class="{ VPNavBarMenuLink: true, active: isActiveLink }"
VPNavBarMenuLink: true,
active: isActive(
page.relativePath,
item.activeMatch || href,
!!item.activeMatch
)
}"
:href :href
:target="item.target" :target="item.target"
:rel="item.rel" :rel="item.rel"

Loading…
Cancel
Save