Skip to content

Commit

Permalink
feat($theme-default): add initial open group index option (#2408)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
dennisreimann committed Aug 3, 2020
1 parent b858a6e commit 465ae40
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
Expand Up @@ -47,6 +47,7 @@
class="sidebar-group-items"
:items="item.children"
:sidebar-depth="item.sidebarDepth"
:initial-open-group-index="item.initialOpenGroupIndex"
:depth="depth + 1"
/>
</DropdownTransition>
Expand Down
5 changes: 3 additions & 2 deletions packages/@vuepress/theme-default/components/SidebarLinks.vue
Expand Up @@ -37,12 +37,13 @@ export default {
props: [
'items',
'depth', // depth of current sidebar links
'sidebarDepth' // depth of headers to be extracted
'sidebarDepth', // depth of headers to be extracted
'initialOpenGroupIndex'
],
data () {
return {
openGroupIndex: 0
openGroupIndex: this.initialOpenGroupIndex || 0
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/@vuepress/theme-default/util/index.js
Expand Up @@ -236,6 +236,7 @@ function resolveItem (item, pages, base, groupDepth = 1) {
path: item.path,
title: item.title,
sidebarDepth: item.sidebarDepth,
initialOpenGroupIndex: item.initialOpenGroupIndex,
children: children.map(child => resolveItem(child, pages, base, groupDepth + 1)),
collapsable: item.collapsable !== false
}
Expand Down
5 changes: 4 additions & 1 deletion packages/docs/docs/theme/default-theme-config.md
Expand Up @@ -220,7 +220,8 @@ module.exports = {
},
{
title: 'Group 2',
children: [ /* ... */ ]
children: [ /* ... */ ],
initialOpenGroupIndex: -1 // optional, defaults to 0, defines the index of initially opened subgroup
}
]
}
Expand All @@ -233,6 +234,8 @@ A sidebar group config also supports [sidebarDepth](#nested-header-links) field

::: tip
   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
Expand Down
3 changes: 2 additions & 1 deletion packages/docs/docs/zh/theme/default-theme-config.md
Expand Up @@ -218,7 +218,8 @@ module.exports = {
},
{
title: 'Group 2',
children: [ /* ... */ ]
children: [ /* ... */ ],
initialOpenGroupIndex: -1 // 可选的, 默认值是 0
}
]
}
Expand Down

0 comments on commit 465ae40

Please sign in to comment.