Skip to content

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

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ module.exports = {
},
{
title: 'Group 2',
children: [ /* ... */ ]
children: [ /* ... */ ],
initialOpenGroupIndex: -1 // 可选的, 默认值是 0
}
]
}
Expand Down