fix(theme): highlight active link in mobile nav menu (#5086) (closes #5068, closes #5074)

pull/5071/merge
seeksky 8 months ago committed by GitHub
parent b2008654ff
commit 923aa90252
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,6 +2,7 @@
import type { DefaultTheme } from 'vitepress/theme' import type { DefaultTheme } from 'vitepress/theme'
import { computed, inject } from 'vue' import { computed, inject } from 'vue'
import { useData } from '../composables/data' import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { navInjectionKey } from '../composables/nav' import { navInjectionKey } from '../composables/nav'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
@ -17,12 +18,20 @@ const href = computed(() =>
: props.item.link : props.item.link
) )
const isActiveLink = computed(() =>
isActive(
page.value.relativePath,
props.item.activeMatch || href.value,
!!props.item.activeMatch
)
)
const { closeScreen } = inject(navInjectionKey)! const { closeScreen } = inject(navInjectionKey)!
</script> </script>
<template> <template>
<VPLink <VPLink
class="VPNavScreenMenuGroupLink" :class="{ VPNavScreenMenuGroupLink: true, active: isActiveLink }"
:href :href
:target="item.target" :target="item.target"
:rel="item.rel" :rel="item.rel"
@ -47,4 +56,8 @@ const { closeScreen } = inject(navInjectionKey)!
.VPNavScreenMenuGroupLink:hover { .VPNavScreenMenuGroupLink:hover {
color: var(--vp-c-brand-1); color: var(--vp-c-brand-1);
} }
.VPNavScreenMenuGroupLink.active {
color: var(--vp-c-brand-1);
}
</style> </style>

@ -2,6 +2,7 @@
import type { DefaultTheme } from 'vitepress/theme' import type { DefaultTheme } from 'vitepress/theme'
import { computed, inject } from 'vue' import { computed, inject } from 'vue'
import { useData } from '../composables/data' import { useData } from '../composables/data'
import { isActive } from '../../shared'
import { navInjectionKey } from '../composables/nav' import { navInjectionKey } from '../composables/nav'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
@ -17,12 +18,20 @@ const href = computed(() =>
: props.item.link : props.item.link
) )
const isActiveLink = computed(() =>
isActive(
page.value.relativePath,
props.item.activeMatch || href.value,
!!props.item.activeMatch
)
)
const { closeScreen } = inject(navInjectionKey)! const { closeScreen } = inject(navInjectionKey)!
</script> </script>
<template> <template>
<VPLink <VPLink
class="VPNavScreenMenuLink" :class="{ VPNavScreenMenuLink: true, active: isActiveLink }"
:href :href
:target="item.target" :target="item.target"
:rel="item.rel" :rel="item.rel"
@ -50,4 +59,8 @@ const { closeScreen } = inject(navInjectionKey)!
.VPNavScreenMenuLink:hover { .VPNavScreenMenuLink:hover {
color: var(--vp-c-brand-1); color: var(--vp-c-brand-1);
} }
.VPNavScreenMenuLink.active {
color: var(--vp-c-brand-1);
}
</style> </style>

Loading…
Cancel
Save