mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-24 14:36:59 +02:00
fix(docs): fix sidebar item visibility bug for category index (#10754)
This commit is contained in:
parent
4966dce36e
commit
91c0b5bf35
6 changed files with 50 additions and 1 deletions
|
@ -440,6 +440,7 @@ describe('isVisibleSidebarItem', () => {
|
||||||
it('works with category', () => {
|
it('works with category', () => {
|
||||||
const subCategoryAllUnlisted = testCategory({
|
const subCategoryAllUnlisted = testCategory({
|
||||||
href: '/sub-category-path',
|
href: '/sub-category-path',
|
||||||
|
linkUnlisted: true,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'link',
|
type: 'link',
|
||||||
|
@ -455,6 +456,7 @@ describe('isVisibleSidebarItem', () => {
|
||||||
},
|
},
|
||||||
testCategory({
|
testCategory({
|
||||||
href: '/sub-sub-category-path',
|
href: '/sub-sub-category-path',
|
||||||
|
linkUnlisted: true,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'link',
|
type: 'link',
|
||||||
|
@ -500,6 +502,22 @@ describe('isVisibleSidebarItem', () => {
|
||||||
expect(
|
expect(
|
||||||
isVisibleSidebarItem(categorySomeUnlisted, categorySomeUnlisted.href!),
|
isVisibleSidebarItem(categorySomeUnlisted, categorySomeUnlisted.href!),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
const categoryOnlyIndexListed = testCategory({
|
||||||
|
href: '/category-only-index-listed',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
type: 'link',
|
||||||
|
href: '/sub-link-path',
|
||||||
|
label: 'Label',
|
||||||
|
unlisted: true,
|
||||||
|
},
|
||||||
|
subCategoryAllUnlisted,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
isVisibleSidebarItem(categoryOnlyIndexListed, '/nonexistentPath'),
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ export function isVisibleSidebarItem(
|
||||||
case 'category':
|
case 'category':
|
||||||
return (
|
return (
|
||||||
isActiveSidebarItem(item, activePath) ||
|
isActiveSidebarItem(item, activePath) ||
|
||||||
|
(typeof item.href !== 'undefined' && !item.linkUnlisted) ||
|
||||||
item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath))
|
item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath))
|
||||||
);
|
);
|
||||||
case 'link':
|
case 'link':
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
unlisted: false
|
||||||
|
tags: [visibility, unlisted]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Subcategory index listed
|
||||||
|
|
||||||
|
Doc index, **listed**, but all the other category items are unlisted
|
||||||
|
|
||||||
|
```mdx-code-block
|
||||||
|
import DocCardList from '@theme/DocCardList';
|
||||||
|
|
||||||
|
<DocCardList />
|
||||||
|
```
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
unlisted: true
|
||||||
|
tags: [visibility, unlisted]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Unlisted 1
|
||||||
|
|
||||||
|
Doc with unlisted front matter
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
unlisted: true
|
||||||
|
tags: [visibility, unlisted]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Unlisted 2
|
||||||
|
|
||||||
|
Doc with unlisted front matter
|
|
@ -3,7 +3,7 @@ unlisted: true
|
||||||
tags: [visibility, unlisted]
|
tags: [visibility, unlisted]
|
||||||
---
|
---
|
||||||
|
|
||||||
# Some Unlisteds - Subcategory index unlisted
|
# Subcategory index unlisted
|
||||||
|
|
||||||
Doc with unlisted front matter
|
Doc with unlisted front matter
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue