mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 13:08:58 +02:00
fix(v2): fix FOUC in doc sidebar and various improvements (#2867)
* bug(v2): fix active sidebar item detection logic (https://github.com/facebook/docusaurus/pull/2682#issuecomment-636631225) * fix sidebar category collapsed normalization to make sure we always have a boolean after normalization * fix sidebarCollapsible option
This commit is contained in:
parent
b8de9c6ded
commit
6797af660f
7 changed files with 131 additions and 137 deletions
|
@ -25,6 +25,9 @@ function isCategoryShorthand(
|
|||
return typeof item !== 'string' && !item.type;
|
||||
}
|
||||
|
||||
// categories are collapsed by default, unless user set collapsed = false
|
||||
const defaultCategoryCollapsedValue = true;
|
||||
|
||||
/**
|
||||
* Convert {category1: [item1,item2]} shorthand syntax to long-form syntax
|
||||
*/
|
||||
|
@ -33,7 +36,7 @@ function normalizeCategoryShorthand(
|
|||
): SidebarItemCategoryRaw[] {
|
||||
return Object.entries(sidebar).map(([label, items]) => ({
|
||||
type: 'category',
|
||||
collapsed: true,
|
||||
collapsed: defaultCategoryCollapsedValue,
|
||||
label,
|
||||
items,
|
||||
}));
|
||||
|
@ -118,7 +121,13 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] {
|
|||
switch (item.type) {
|
||||
case 'category':
|
||||
assertIsCategory(item);
|
||||
return [{...item, items: flatMap(item.items, normalizeItem)}];
|
||||
return [
|
||||
{
|
||||
collapsed: defaultCategoryCollapsedValue,
|
||||
...item,
|
||||
items: flatMap(item.items, normalizeItem),
|
||||
},
|
||||
];
|
||||
case 'link':
|
||||
assertIsLink(item);
|
||||
return [item];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue