Skip to content

Commit

Permalink
hopefully a better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pranabdas committed May 14, 2022
1 parent f25b705 commit 7997c73
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,23 @@ import useIsBrowser from '@docusaurus/useIsBrowser';
function useAutoExpandActiveCategory({
isActive,
collapsed,
index,
setCollapsed,
}: {
isActive: boolean;
collapsed: boolean;
index: number;
setCollapsed: (b: boolean) => void;
}) {
const wasActive = usePrevious(isActive);
const {
docs: {
sidebar: {autoCollapseCategories},
},
} = useThemeConfig();
const {setExpandedItem} = useDocSidebarItemsExpandedState();
useEffect(() => {
const justBecameActive = isActive && !wasActive;
if (justBecameActive && collapsed) {
setCollapsed(false);
setExpandedItem(index);
}
if (autoCollapseCategories && !isActive && wasActive) {
setCollapsed(true);
}
}, [isActive, wasActive, collapsed, setCollapsed, autoCollapseCategories]);
}, [isActive, wasActive, collapsed, setCollapsed, setExpandedItem, index]);
}

/**
Expand Down Expand Up @@ -129,7 +125,7 @@ export default function DocSidebarItemCategory({
},
});

useAutoExpandActiveCategory({isActive, collapsed, setCollapsed});
useAutoExpandActiveCategory({isActive, collapsed, index, setCollapsed});
const {expandedItem, setExpandedItem} = useDocSidebarItemsExpandedState();
function updateCollapsed(toCollapsed: boolean = !collapsed) {
setExpandedItem(toCollapsed ? null : index);
Expand All @@ -148,8 +144,16 @@ export default function DocSidebarItemCategory({
autoCollapseCategories
) {
setCollapsed(true);
setExpandedItem(null);
}
}, [collapsible, expandedItem, index, setCollapsed, autoCollapseCategories]);
}, [
collapsible,
expandedItem,
index,
setCollapsed,
setExpandedItem,
autoCollapseCategories,
]);

return (
<li
Expand Down

0 comments on commit 7997c73

Please sign in to comment.