Skip to content

Commit

Permalink
fix: calculate sidebar height error (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
uucoding committed Jun 4, 2023
1 parent e0e2b1f commit 584ffc9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/island/src/theme-default/components/Siderbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ export function SideBar(props: Props & ComponentPropsWithIsland) {
}}
></div>
);
const countItems = (items: DefaultTheme.SidebarItem[]) => {
if (!items) return 0;
let count = 0;
for (const item of items) {
count++;
if ('items' in item) {
count += countItems(item.items || []);
}
}
return count;
};
const count = countItems(item.items);
return (
<section key={item.text} block="~" not-first="divider-top mt-4">
<div
Expand All @@ -88,7 +100,7 @@ export function SideBar(props: Props & ComponentPropsWithIsland) {
mb="1.4 sm:1"
style={{
transition: 'height 0.2s ease-out',
height: collapsed ? 0 : `${(item?.items.length || 0) * 28}px`,
height: collapsed ? 0 : `${count * 28}px`,
overflow: 'hidden'
}}
>
Expand Down

1 comment on commit 584ffc9

@vercel
Copy link

@vercel vercel bot commented on 584ffc9 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.