未验证 提交 465ae40d 编写于 作者: D Dennis Reimann 提交者: GitHub

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`
上级 b858a6ee
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
class="sidebar-group-items" class="sidebar-group-items"
:items="item.children" :items="item.children"
:sidebar-depth="item.sidebarDepth" :sidebar-depth="item.sidebarDepth"
:initial-open-group-index="item.initialOpenGroupIndex"
:depth="depth + 1" :depth="depth + 1"
/> />
</DropdownTransition> </DropdownTransition>
......
...@@ -37,12 +37,13 @@ export default { ...@@ -37,12 +37,13 @@ export default {
props: [ props: [
'items', 'items',
'depth', // depth of current sidebar links 'depth', // depth of current sidebar links
'sidebarDepth' // depth of headers to be extracted 'sidebarDepth', // depth of headers to be extracted
'initialOpenGroupIndex'
], ],
data () { data () {
return { return {
openGroupIndex: 0 openGroupIndex: this.initialOpenGroupIndex || 0
} }
}, },
......
...@@ -236,6 +236,7 @@ function resolveItem (item, pages, base, groupDepth = 1) { ...@@ -236,6 +236,7 @@ function resolveItem (item, pages, base, groupDepth = 1) {
path: item.path, path: item.path,
title: item.title, title: item.title,
sidebarDepth: item.sidebarDepth, sidebarDepth: item.sidebarDepth,
initialOpenGroupIndex: item.initialOpenGroupIndex,
children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)), children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)),
collapsable: item.collapsable !== false collapsable: item.collapsable !== false
} }
......
...@@ -220,7 +220,8 @@ module.exports = { ...@@ -220,7 +220,8 @@ module.exports = {
}, },
{ {
title: 'Group 2', title: 'Group 2',
children: [ /* ... */ ] children: [ /* ... */ ],
initialOpenGroupIndex: -1 // optional, defaults to 0, defines the index of initially opened subgroup
} }
] ]
} }
...@@ -233,6 +234,8 @@ A sidebar group config also supports [sidebarDepth](#nested-header-links) field ...@@ -233,6 +234,8 @@ A sidebar group config also supports [sidebarDepth](#nested-header-links) field
::: tip ::: tip
   Nested sidebar group is also supported.    Nested sidebar group is also supported.
By default the first subgroup is opened initially.
You can change this using the `initialOpenGroupIndex`: Specify an index to open another subgroup or use `-1` for no open group.
::: :::
### Multiple Sidebars ### Multiple Sidebars
......
...@@ -218,7 +218,8 @@ module.exports = { ...@@ -218,7 +218,8 @@ module.exports = {
}, },
{ {
title: 'Group 2', title: 'Group 2',
children: [ /* ... */ ] children: [ /* ... */ ],
initialOpenGroupIndex: -1 // 可选的, 默认值是 0
} }
] ]
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册