Skip to content

Commit

Permalink
fix(@clayui/core): fixes error when having condition in the children …
Browse files Browse the repository at this point in the history
…of TreeView.Item and TreeView.ItemStack the last element is positioned to the right

Using `React.Children.toArray` brings the result different from `React.Children.map`, apparently when you have conditionals, some elements are `Array<Array<any>>` while `React.Children.map` brings a flat array, we use `React.Children.count` because it is safer here and brings the exact count of elements as children.
  • Loading branch information
matuzalemsteles committed Feb 14, 2022
1 parent 6ae276a commit 0e121d3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/clay-core/src/tree-view/TreeViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export function TreeViewItemStack({

const item = useItem();

const childrenArray = React.Children.toArray(children);
const childrenCount = React.Children.count(children);

const nestedChildren =
nestedKey && (item[nestedKey] as Array<Record<string, any>>);
Expand Down Expand Up @@ -503,9 +503,7 @@ export function TreeViewItemStack({
}

return (
<Layout.ContentCol
expand={index === childrenArray.length - 1}
>
<Layout.ContentCol expand={index === childrenCount - 1}>
{content}
</Layout.ContentCol>
);
Expand Down

0 comments on commit 0e121d3

Please sign in to comment.