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

fix(VPSidebarItem): use depth and index as the key #3621

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/client/theme-default/components/VPSidebarItem.vue
Expand Up @@ -97,8 +97,8 @@ function onCaretClick() {
<div v-if="item.items && item.items.length" class="items">
<template v-if="depth < 5">
<VPSidebarItem
v-for="i in item.items"
:key="i.text"
v-for="(i, j) in item.items"
:key="`${depth}-${j}`"
:item="i"
:depth="depth + 1"
/>
Expand Down
13 changes: 9 additions & 4 deletions src/client/theme-default/composables/sidebar.ts
Expand Up @@ -7,7 +7,6 @@ import {
ref,
watch,
watchEffect,
watchPostEffect,
type ComputedRef,
type Ref
} from 'vue'
Expand Down Expand Up @@ -176,9 +175,15 @@ export function useSidebarControl(
collapsed.value = !!(collapsible.value && item.value.collapsed)
})

watchPostEffect(() => {
;(isActiveLink.value || hasActiveLink.value) && (collapsed.value = false)
})
watch(
item,
() => {
if (isActiveLink.value || hasActiveLink.value) {
collapsed.value = false
}
},
{ immediate: true, deep: true }
)

function toggle() {
if (collapsible.value) {
Expand Down