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

fix(v2): do not show category with empty items #1891

Merged
merged 1 commit into from
Oct 26, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix search bar focus bug. When you put the focus on search input, previously the focus will remain although we have clicked to other area outside of the search input.
- New themeConfig option `sidebarCollapsible`. It is on by default. If explicitly set to `false`, all doc items in sidebar is expanded. Otherwise, it will still be a collapsible sidebar.
- Disable adding hashes to the generated class names of CSS modules in dev mode. Generating unique identifiers takes some time, which can be saved since including paths to files in class names is enough to avoid collisions.
- Fix showing sidebar category with empty items.

## 2.0.0-alpha.30

Expand Down
75 changes: 41 additions & 34 deletions packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,35 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
switch (type) {
case 'category':
return (
<li
className={classnames('menu__list-item', {
'menu__list-item--collapsed': collapsed,
})}
key={label}>
<a
className={classnames('menu__link', {
'menu__link--sublist': collapsible,
'menu__link--active': collapsible && !item.collapsed,
items.length > 0 && (
<li
className={classnames('menu__list-item', {
'menu__list-item--collapsed': collapsed,
})}
href="#!"
onClick={collapsible ? () => setCollapsed(!collapsed) : undefined}>
{label}
</a>
<ul className="menu__list">
{items.map(childItem => (
<DocSidebarItem
key={childItem.label}
item={childItem}
onItemClick={onItemClick}
collapsible={collapsible}
/>
))}
</ul>
</li>
key={label}>
<a
className={classnames('menu__link', {
'menu__link--sublist': collapsible,
'menu__link--active': collapsible && !item.collapsed,
})}
href="#!"
onClick={
collapsible ? () => setCollapsed(!collapsed) : undefined
}>
{label}
</a>
<ul className="menu__list">
{items.map(childItem => (
<DocSidebarItem
key={childItem.label}
item={childItem}
onItemClick={onItemClick}
collapsible={collapsible}
/>
))}
</ul>
</li>
)
);

case 'link':
Expand Down Expand Up @@ -164,16 +168,19 @@ function DocSidebar(props) {
)}
</button>
<ul className="menu__list">
{sidebarData.map(item => (
<DocSidebarItem
key={item.label}
item={item}
onItemClick={() => {
setShowResponsiveSidebar(false);
}}
collapsible={sidebarCollapsible}
/>
))}
{sidebarData.map(
item =>
item.items.length > 0 && (
<DocSidebarItem
key={item.label}
item={item}
onItemClick={() => {
setShowResponsiveSidebar(false);
}}
collapsible={sidebarCollapsible}
/>
),
)}
</ul>
</div>
</div>
Expand Down