Skip to content

Commit

Permalink
filter out null children in buttongroup (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 authored May 15, 2023
1 parent 5cfd0bb commit c533796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/purple-beds-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Fixed an issue in ButtonGroup where null/undefined children were also getting wrapped by empty `<div>`s.
5 changes: 4 additions & 1 deletion packages/itwinui-react/src/core/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
} = props;

const items = React.useMemo(
() => React.Children.map(children, (child) => <div>{child}</div>) ?? [],
() =>
React.Children.map(children, (child) =>
!!child ? <div>{child}</div> : undefined,
)?.filter(Boolean) ?? [],
[children],
);

Expand Down

0 comments on commit c533796

Please sign in to comment.