From 290142a356675c34c5ab47477141a2bd7d5d81f6 Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Sat, 13 Apr 2019 12:12:04 +0200 Subject: [PATCH 1/5] Fix #1497 expanad nested sidebar items initially --- .../theme-default/components/SidebarLinks.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLinks.vue b/packages/@vuepress/theme-default/components/SidebarLinks.vue index dfdb0bef07..1521b7e2ba 100644 --- a/packages/@vuepress/theme-default/components/SidebarLinks.vue +++ b/packages/@vuepress/theme-default/components/SidebarLinks.vue @@ -77,10 +77,23 @@ export default { function resolveOpenGroupIndex (route, items) { for (let i = 0; i < items.length; i++) { const item = items[i] - if (item.type === 'group' && item.children.some(c => c.type === 'page' && isActive(route, c.path))) { + if (descendantIsActive(route, item)) { return i } } return -1 } + +function descendantIsActive (route, item) { + if (item.type === 'group') { + return item.children.some(c => { + if (c.type === 'group') { + return descendantIsActive(route, c) + } else { + return c.type === 'page' && isActive(route, c.path) + } + }) + } + return false +} From b9f262b1aba17961744e20ba8ce0fd67b15728ce Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Tue, 10 Sep 2019 22:17:15 +0200 Subject: [PATCH 2/5] improve variable name Co-Authored-By: Franck Abgrall --- packages/@vuepress/theme-default/components/SidebarLinks.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLinks.vue b/packages/@vuepress/theme-default/components/SidebarLinks.vue index 1521b7e2ba..5946280818 100644 --- a/packages/@vuepress/theme-default/components/SidebarLinks.vue +++ b/packages/@vuepress/theme-default/components/SidebarLinks.vue @@ -86,7 +86,7 @@ function resolveOpenGroupIndex (route, items) { function descendantIsActive (route, item) { if (item.type === 'group') { - return item.children.some(c => { + return item.children.some(child => { if (c.type === 'group') { return descendantIsActive(route, c) } else { From 5083abd808edb11b6d4a38f2d441beeb177894db Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Tue, 10 Sep 2019 22:19:13 +0200 Subject: [PATCH 3/5] improve variable name Co-Authored-By: Franck Abgrall --- packages/@vuepress/theme-default/components/SidebarLinks.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLinks.vue b/packages/@vuepress/theme-default/components/SidebarLinks.vue index 5946280818..ffc9477e18 100644 --- a/packages/@vuepress/theme-default/components/SidebarLinks.vue +++ b/packages/@vuepress/theme-default/components/SidebarLinks.vue @@ -87,7 +87,7 @@ function resolveOpenGroupIndex (route, items) { function descendantIsActive (route, item) { if (item.type === 'group') { return item.children.some(child => { - if (c.type === 'group') { + if (child.type === 'group') { return descendantIsActive(route, c) } else { return c.type === 'page' && isActive(route, c.path) From bb18ccad6b1039ff7807c002f1d65b8cbd541f44 Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Tue, 10 Sep 2019 22:19:24 +0200 Subject: [PATCH 4/5] improve variable name Co-Authored-By: Franck Abgrall --- packages/@vuepress/theme-default/components/SidebarLinks.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLinks.vue b/packages/@vuepress/theme-default/components/SidebarLinks.vue index ffc9477e18..8ae2bac309 100644 --- a/packages/@vuepress/theme-default/components/SidebarLinks.vue +++ b/packages/@vuepress/theme-default/components/SidebarLinks.vue @@ -90,7 +90,7 @@ function descendantIsActive (route, item) { if (child.type === 'group') { return descendantIsActive(route, c) } else { - return c.type === 'page' && isActive(route, c.path) + return child.type === 'page' && isActive(route, child.path) } }) } From 4b4e0ced07feb5512b012109dd87b631d3ade49f Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Tue, 10 Sep 2019 22:19:37 +0200 Subject: [PATCH 5/5] improve variable name Co-Authored-By: Franck Abgrall --- packages/@vuepress/theme-default/components/SidebarLinks.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLinks.vue b/packages/@vuepress/theme-default/components/SidebarLinks.vue index 8ae2bac309..d6b5ff7cdb 100644 --- a/packages/@vuepress/theme-default/components/SidebarLinks.vue +++ b/packages/@vuepress/theme-default/components/SidebarLinks.vue @@ -88,7 +88,7 @@ function descendantIsActive (route, item) { if (item.type === 'group') { return item.children.some(child => { if (child.type === 'group') { - return descendantIsActive(route, c) + return descendantIsActive(route, child) } else { return child.type === 'page' && isActive(route, child.path) }