Skip to content

Commit fcc5312

Browse files
janvennemannsgtcoolguy
authored andcommitted
fix: mark all nested sidebar items active
1 parent 1e28793 commit fcc5312

File tree

1 file changed

+6
-12
lines changed
  • packages/vuepress/vuepress-theme-titanium/components

1 file changed

+6
-12
lines changed

packages/vuepress/vuepress-theme-titanium/components/Sidebar.vue

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,16 @@ export default {
6262
}
6363
}
6464
65-
function markActiveItemRecursive (item, currentAnchor, depth = 0) {
65+
function markActiveItemRecursive (item, currentAnchor) {
6666
const selfActive = isActive(currentAnchor, item.path)
6767
let active = selfActive
68-
if (item.type === 'auto') {
68+
if (item.children) {
6969
let childActive = false
7070
for (const c of item.children) {
71-
c.path = item.basePath + '#' + c.slug
72-
if (markActiveItemRecursive(c, currentAnchor, depth + 1)) {
73-
childActive = true
71+
if (!c.path) {
72+
c.path = item.path.replace(hashRE, '') + '#' + c.slug
7473
}
75-
}
76-
active = selfActive || childActive
77-
} else if (item.type === 'group') {
78-
let childActive = false
79-
for (const c of item.children) {
80-
if (markActiveItemRecursive(c, currentAnchor, depth + 1)) {
74+
if (markActiveItemRecursive(c, currentAnchor)) {
8175
childActive = true
8276
}
8377
}
@@ -87,7 +81,7 @@ function markActiveItemRecursive (item, currentAnchor, depth = 0) {
8781
const children = groupHeaders(item.headers)
8882
for (const c of children) {
8983
c.path = item.path + '#' + c.slug
90-
if (markActiveItemRecursive(c, currentAnchor, depth + 1)) {
84+
if (markActiveItemRecursive(c, currentAnchor)) {
9185
childActive = true
9286
}
9387
}

0 commit comments

Comments
 (0)