Skip to content

Commit 91c0b5b

Browse files
authored
fix(docs): fix sidebar item visibility bug for category index (#10754)
1 parent 4966dce commit 91c0b5b

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

packages/docusaurus-plugin-content-docs/src/client/__tests__/docsUtils.test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ describe('isVisibleSidebarItem', () => {
440440
it('works with category', () => {
441441
const subCategoryAllUnlisted = testCategory({
442442
href: '/sub-category-path',
443+
linkUnlisted: true,
443444
items: [
444445
{
445446
type: 'link',
@@ -455,6 +456,7 @@ describe('isVisibleSidebarItem', () => {
455456
},
456457
testCategory({
457458
href: '/sub-sub-category-path',
459+
linkUnlisted: true,
458460
items: [
459461
{
460462
type: 'link',
@@ -500,6 +502,22 @@ describe('isVisibleSidebarItem', () => {
500502
expect(
501503
isVisibleSidebarItem(categorySomeUnlisted, categorySomeUnlisted.href!),
502504
).toBe(true);
505+
506+
const categoryOnlyIndexListed = testCategory({
507+
href: '/category-only-index-listed',
508+
items: [
509+
{
510+
type: 'link',
511+
href: '/sub-link-path',
512+
label: 'Label',
513+
unlisted: true,
514+
},
515+
subCategoryAllUnlisted,
516+
],
517+
});
518+
expect(
519+
isVisibleSidebarItem(categoryOnlyIndexListed, '/nonexistentPath'),
520+
).toBe(true);
503521
});
504522
});
505523

packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export function isVisibleSidebarItem(
168168
case 'category':
169169
return (
170170
isActiveSidebarItem(item, activePath) ||
171+
(typeof item.href !== 'undefined' && !item.linkUnlisted) ||
171172
item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath))
172173
);
173174
case 'link':
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
unlisted: false
3+
tags: [visibility, unlisted]
4+
---
5+
6+
# Subcategory index listed
7+
8+
Doc index, **listed**, but all the other category items are unlisted
9+
10+
```mdx-code-block
11+
import DocCardList from '@theme/DocCardList';
12+
13+
<DocCardList />
14+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
unlisted: true
3+
tags: [visibility, unlisted]
4+
---
5+
6+
# Unlisted 1
7+
8+
Doc with unlisted front matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
unlisted: true
3+
tags: [visibility, unlisted]
4+
---
5+
6+
# Unlisted 2
7+
8+
Doc with unlisted front matter

website/_dogfooding/_docs tests/tests/visibility/some-unlisteds/unlisted-subcategory/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ unlisted: true
33
tags: [visibility, unlisted]
44
---
55

6-
# Some Unlisteds - Subcategory index unlisted
6+
# Subcategory index unlisted
77

88
Doc with unlisted front matter
99

0 commit comments

Comments
 (0)