diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-category.js b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-category.js index 975f1203fe..402803c0c4 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-category.js +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-category.js @@ -9,30 +9,25 @@ module.exports = { docs: [ { type: 'category', - collapsed: true, label: 'level 1', items: [ 'a', { type: 'category', - collapsed: true, label: 'level 2', items: [ { type: 'category', - collapsed: true, label: 'level 3', items: [ 'c', { type: 'category', - collapsed: true, label: 'level 4', items: [ 'd', { type: 'category', - collapsed: true, label: 'deeper more more', items: ['e'], }, diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json deleted file mode 100644 index 1251a7d454..0000000000 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "docs": [ - { - "type": "category", - "label": "Introduction", - "items": [ - "doc1" - ], - "collapsed": false - }, - { - "type": "category", - "label": "Powering MDX", - "items": [ - "doc2" - ], - "collapsed": false - } - ] -} \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json deleted file mode 100644 index 2199c5f557..0000000000 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "docs": { - "Test": [ - { - "type": "category", - "label": "Introduction", - "items": ["doc1"], - "collapsed": false - } - ], - "Reference": [ - { - "type": "category", - "label": "Powering MDX", - "items": ["doc2"], - "collapsed": false - } - ] - } - } - \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap index dd85d4c264..11d22b0c99 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap @@ -4,7 +4,6 @@ exports[`simple website content 1`] = ` Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "items": Array [ @@ -37,7 +36,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/hello", @@ -202,7 +200,6 @@ exports[`versioned website content: all sidebars 1`] = ` Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/next/foo/bar", @@ -214,7 +211,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/next/hello", @@ -228,7 +224,6 @@ Object { ], "version-1.0.0/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/1.0.0/foo/bar", @@ -245,7 +240,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/1.0.0/hello", @@ -259,7 +253,6 @@ Object { ], "version-1.0.1/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/foo/bar", @@ -271,7 +264,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/hello", @@ -291,7 +283,6 @@ Object { "docsSidebars": Object { "version-1.0.0/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/1.0.0/foo/bar", @@ -308,7 +299,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/1.0.0/hello", @@ -335,7 +325,6 @@ Object { "docsSidebars": Object { "version-1.0.1/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/foo/bar", @@ -347,7 +336,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/hello", @@ -373,7 +361,6 @@ Object { "docsSidebars": Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/next/foo/bar", @@ -385,7 +372,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "href": "/docs/next/hello", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.ts.snap index 0aa670c44b..e0bc01bdc9 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.ts.snap @@ -4,7 +4,6 @@ exports[`loadSidebars sidebars link 1`] = ` Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "href": "https://github.com", @@ -19,107 +18,30 @@ Object { } `; -exports[`loadSidebars sidebars with category.collapsed property 1`] = ` -Object { - "docs": Array [ - Object { - "collapsed": true, - "items": Array [ - Object { - "collapsed": false, - "items": Array [ - Object { - "id": "doc1", - "type": "doc", - }, - ], - "label": "Introduction", - "type": "category", - }, - ], - "label": "Test", - "type": "category", - }, - Object { - "collapsed": true, - "items": Array [ - Object { - "collapsed": false, - "items": Array [ - Object { - "id": "doc2", - "type": "doc", - }, - ], - "label": "Powering MDX", - "type": "category", - }, - ], - "label": "Reference", - "type": "category", - }, - ], -} -`; - -exports[`loadSidebars sidebars with category.collapsed property at first level 1`] = ` -Object { - "docs": Array [ - Object { - "collapsed": false, - "items": Array [ - Object { - "id": "doc1", - "type": "doc", - }, - ], - "label": "Introduction", - "type": "category", - }, - Object { - "collapsed": false, - "items": Array [ - Object { - "id": "doc2", - "type": "doc", - }, - ], - "label": "Powering MDX", - "type": "category", - }, - ], -} -`; - exports[`loadSidebars sidebars with deep level of category 1`] = ` Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "id": "a", "type": "doc", }, Object { - "collapsed": true, "items": Array [ Object { - "collapsed": true, "items": Array [ Object { "id": "c", "type": "doc", }, Object { - "collapsed": true, "items": Array [ Object { "id": "d", "type": "doc", }, Object { - "collapsed": true, "items": Array [ Object { "id": "e", @@ -178,7 +100,6 @@ exports[`loadSidebars sidebars with known sidebar item type 1`] = ` Object { "docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "id": "foo/bar", @@ -202,7 +123,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "id": "hello", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/version.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/version.test.ts.snap index 26c10f3c0a..47ffaef77f 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/version.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/version.test.ts.snap @@ -4,7 +4,6 @@ exports[`docsVersion first time versioning 1`] = ` Object { "version-1.0.0/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "items": Array [ @@ -34,7 +33,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "id": "version-1.0.0/hello", @@ -52,7 +50,6 @@ exports[`docsVersion not the first time versioning 1`] = ` Object { "version-2.0.0/docs": Array [ Object { - "collapsed": true, "items": Array [ Object { "id": "version-2.0.0/foo/bar", @@ -63,7 +60,6 @@ Object { "type": "category", }, Object { - "collapsed": true, "items": Array [ Object { "id": "version-2.0.0/hello", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.ts index 11d882b22a..49a788dfd9 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.ts @@ -126,19 +126,4 @@ describe('loadSidebars', () => { const result = loadSidebars(null); expect(result).toEqual({}); }); - - test('sidebars with category.collapsed property', async () => { - const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json'); - const result = loadSidebars([sidebarPath]); - expect(result).toMatchSnapshot(); - }); - - test('sidebars with category.collapsed property at first level', async () => { - const sidebarPath = path.join( - fixtureDir, - 'sidebars-collapsed-first-level.json', - ); - const result = loadSidebars([sidebarPath]); - expect(result).toMatchSnapshot(); - }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars.ts b/packages/docusaurus-plugin-content-docs/src/sidebars.ts index abe988984b..cfe1b36254 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars.ts @@ -33,7 +33,6 @@ function normalizeCategoryShorthand( ): SidebarItemCategoryRaw[] { return Object.entries(sidebar).map(([label, items]) => ({ type: 'category', - collapsed: true, label, items, })); @@ -57,7 +56,7 @@ function assertItem(item: Object, keys: string[]): void { } function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw { - assertItem(item, ['items', 'label', 'collapsed']); + assertItem(item, ['items', 'label']); if (typeof item.label !== 'string') { throw new Error( `Error loading ${JSON.stringify(item)}. "label" must be a string.`, @@ -68,12 +67,6 @@ function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw { `Error loading ${JSON.stringify(item)}. "items" must be an array.`, ); } - // "collapsed" is an optional property - if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') { - throw new Error( - `Error loading ${JSON.stringify(item)}. "collapsed" must be a boolean.`, - ); - } } function assertIsDoc(item: any): asserts item is SidebarItemDoc { diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index 9516cec3f7..4929797c59 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -40,14 +40,12 @@ export interface SidebarItemCategory { type: 'category'; label: string; items: SidebarItem[]; - collapsed?: boolean; } export interface SidebarItemCategoryRaw { type: 'category'; label: string; items: SidebarItemRaw[]; - collapsed?: boolean; } export type SidebarItem = @@ -83,7 +81,6 @@ export interface DocsSidebarItemCategory { type: 'category'; label: string; items: DocsSidebarItem[]; - collapsed?: boolean; } export type DocsSidebarItem = SidebarItemLink | DocsSidebarItemCategory; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js index 29bdfa2b70..c59c3611f4 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js @@ -105,11 +105,8 @@ function mutateSidebarCollapsingState(item, path) { items .map((childItem) => mutateSidebarCollapsingState(childItem, path)) .filter((val) => val).length > 0; - // only modify item.collapsed if there are child items active and the category collapsed is set to true - if (anyChildItemsActive && item.collapsed) { - // eslint-disable-next-line no-param-reassign - item.collapsed = !anyChildItemsActive; - } + // eslint-disable-next-line no-param-reassign + item.collapsed = !anyChildItemsActive; return anyChildItemsActive; } diff --git a/website/docs/docs.md b/website/docs/docs.md index b46a67309f..d44c89ebed 100644 --- a/website/docs/docs.md +++ b/website/docs/docs.md @@ -207,7 +207,6 @@ type SidebarItemCategory = { type: 'category'; label: string; // Sidebar label text. items: SidebarItem[]; // Array of sidebar items. - collapsed: boolean; // Set the category to be collapsed or open by default }; ```