Skip to content

Commit

Permalink
fix(DropdownContent): Handle false as child (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvalaura authored Oct 2, 2023
1 parent 99a9090 commit caa2c7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dropdownContent-falseChild.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': patch
---

fix(DropdownContent): Handle `false` as child
16 changes: 16 additions & 0 deletions packages/react-magma-dom/src/components/Dropdown/Dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,20 @@ describe('Dropdown', () => {
jest.useRealTimers();
});
});

it('should not render the false child', () => {
const visible = false;
const { queryByText } = render(
<Dropdown>
<DropdownButton>Toggle me</DropdownButton>
<DropdownMenuGroup header="header">
{visible && <DropdownMenuItem>Menu Item 1</DropdownMenuItem>}
<DropdownMenuItem>Menu Item 2</DropdownMenuItem>
</DropdownMenuGroup>
</Dropdown>
);

expect(queryByText('Menu Item 1')).not.toBeInTheDocument();
expect(queryByText('Menu Item 2')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export const DropdownContent = React.forwardRef<

React.Children.forEach(children, (child: any) => {
if (
child.type?.displayName === 'DropdownMenuItem' ||
child.type?.displayName === 'DropdownMenuGroup'
child?.type?.displayName === 'DropdownMenuItem' ||
child?.type?.displayName === 'DropdownMenuGroup'
) {
hasItemChildren = true;
return;
Expand Down

2 comments on commit caa2c7b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

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.