Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat($theme-default): add initial open group index option #2408

Merged
merged 2 commits into from Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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