Skip to content

Commit 465ae40

Browse files
authoredAug 3, 2020
feat($theme-default): add initial open group index option (#2408)
* feat($theme-default): add initial open group index option Adds an optional property for sidebar groups, so that one can initially display a group other than the first as open. Also allows to initially display all groups as closed, by setting `initialOpenGroupIndex` to `-1`. * docs: add details on `initialOpenGroupIndex`
1 parent b858a6e commit 465ae40

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed
 

‎packages/@vuepress/theme-default/components/SidebarGroup.vue

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
class="sidebar-group-items"
4848
:items="item.children"
4949
:sidebar-depth="item.sidebarDepth"
50+
:initial-open-group-index="item.initialOpenGroupIndex"
5051
:depth="depth + 1"
5152
/>
5253
</DropdownTransition>

‎packages/@vuepress/theme-default/components/SidebarLinks.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ export default {
3737
props: [
3838
'items',
3939
'depth', // depth of current sidebar links
40-
'sidebarDepth' // depth of headers to be extracted
40+
'sidebarDepth', // depth of headers to be extracted
41+
'initialOpenGroupIndex'
4142
],
4243
4344
data () {
4445
return {
45-
openGroupIndex: 0
46+
openGroupIndex: this.initialOpenGroupIndex || 0
4647
}
4748
},
4849

‎packages/@vuepress/theme-default/util/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ function resolveItem (item, pages, base, groupDepth = 1) {
236236
path: item.path,
237237
title: item.title,
238238
sidebarDepth: item.sidebarDepth,
239+
initialOpenGroupIndex: item.initialOpenGroupIndex,
239240
children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)),
240241
collapsable: item.collapsable !== false
241242
}

‎packages/docs/docs/theme/default-theme-config.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ module.exports = {
220220
},
221221
{
222222
title: 'Group 2',
223-
children: [ /* ... */ ]
223+
children: [ /* ... */ ],
224+
initialOpenGroupIndex: -1 // optional, defaults to 0, defines the index of initially opened subgroup
224225
}
225226
]
226227
}
@@ -233,6 +234,8 @@ A sidebar group config also supports [sidebarDepth](#nested-header-links) field
233234

234235
::: tip
235236
   Nested sidebar group is also supported.
237+
By default the first subgroup is opened initially.
238+
You can change this using the `initialOpenGroupIndex`: Specify an index to open another subgroup or use `-1` for no open group.
236239
:::
237240

238241
### Multiple Sidebars

‎packages/docs/docs/zh/theme/default-theme-config.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ module.exports = {
218218
},
219219
{
220220
title: 'Group 2',
221-
children: [ /* ... */ ]
221+
children: [ /* ... */ ],
222+
initialOpenGroupIndex: -1 // 可选的, 默认值是 0
222223
}
223224
]
224225
}

0 commit comments

Comments
 (0)
Please sign in to comment.