Skip to content

Commit b28667b

Browse files
WizardsBowlbrc-dd
andauthored
fix(theme): navbar menu group is incorrectly highlighted (#5113)
--------- Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
1 parent 2e36f5c commit b28667b

3 files changed

Lines changed: 34 additions & 26 deletions

File tree

src/client/theme-default/components/VPMenuLink.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ const href = computed(() =>
1818
: props.item.link
1919
)
2020
21+
const isActiveLink = computed(() =>
22+
isActive(
23+
page.value.relativePath,
24+
props.item.activeMatch || href.value,
25+
!!props.item.activeMatch
26+
)
27+
)
28+
2129
defineOptions({ inheritAttrs: false })
2230
</script>
2331

2432
<template>
2533
<div class="VPMenuLink">
2634
<VPLink
2735
v-bind="$attrs"
28-
:class="{
29-
active: isActive(
30-
page.relativePath,
31-
item.activeMatch || href,
32-
!!item.activeMatch
33-
)
34-
}"
36+
:class="{ active: isActiveLink }"
3537
:href
3638
:target="item.target"
3739
:rel="props.rel ?? item.rel"

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,36 @@ const props = defineProps<{
1111
1212
const { page } = useData()
1313
14-
const isChildActive = (navItem: DefaultTheme.NavItem) => {
14+
const isActiveGroup = computed(() => {
15+
if (props.item.activeMatch) {
16+
return isActive(page.value.relativePath, props.item.activeMatch, true)
17+
}
18+
return isChildActive(props.item)
19+
})
20+
21+
function isChildActive(navItem: DefaultTheme.NavItem): boolean {
1522
if ('component' in navItem) return false
1623
1724
if ('link' in navItem) {
25+
const href =
26+
typeof navItem.link === 'function'
27+
? navItem.link(page.value)
28+
: navItem.link
29+
1830
return isActive(
1931
page.value.relativePath,
20-
typeof navItem.link === "function" ? navItem.link(page.value) : navItem.link,
21-
!!props.item.activeMatch
32+
navItem.activeMatch || href,
33+
!!navItem.activeMatch
2234
)
2335
}
2436
2537
return navItem.items.some(isChildActive)
2638
}
27-
28-
const childrenActive = computed(() => isChildActive(props.item))
2939
</script>
3040

3141
<template>
3242
<VPFlyout
33-
:class="{
34-
VPNavBarMenuGroup: true,
35-
active:
36-
isActive(page.relativePath, item.activeMatch, !!item.activeMatch) ||
37-
childrenActive
38-
}"
43+
:class="{ VPNavBarMenuGroup: true, active: isActiveGroup }"
3944
:button="item.text"
4045
:items="item.items"
4146
/>

src/client/theme-default/components/VPNavBarMenuLink.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ const href = computed(() =>
1616
? props.item.link(page.value)
1717
: props.item.link
1818
)
19+
20+
const isActiveLink = computed(() =>
21+
isActive(
22+
page.value.relativePath,
23+
props.item.activeMatch || href.value,
24+
!!props.item.activeMatch
25+
)
26+
)
1927
</script>
2028

2129
<template>
2230
<VPLink
23-
:class="{
24-
VPNavBarMenuLink: true,
25-
active: isActive(
26-
page.relativePath,
27-
item.activeMatch || href,
28-
!!item.activeMatch
29-
)
30-
}"
31+
:class="{ VPNavBarMenuLink: true, active: isActiveLink }"
3132
:href
3233
:target="item.target"
3334
:rel="item.rel"

0 commit comments

Comments
 (0)