Skip to content

Commit

Permalink
fix(v2): do not show categories with empty items (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored and yangshun committed Oct 26, 2019
1 parent a9f752c commit 60a4d1d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
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

0 comments on commit 60a4d1d

Please sign in to comment.