Skip to content

Commit

Permalink
[material-ui][Avatar] Improve fallback when children is empty strin…
Browse files Browse the repository at this point in the history
…g or boolean (#40766)

Co-authored-by: ZeeshanTamboli <zeeshan.tamboli@gmail.com>
  • Loading branch information
mirus-ua and ZeeshanTamboli committed Jan 28, 2024
1 parent e6f43be commit 0ebf32f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-material/src/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const Avatar = React.forwardRef(function Avatar(inProps, ref) {
{...imgProps}
/>
);
} else if (childrenProp != null) {
} else if (childrenProp != null && childrenProp !== '' && typeof childrenProp !== 'boolean') {
children = childrenProp;
} else if (hasImg && alt) {
children = alt[0];
Expand Down
14 changes: 14 additions & 0 deletions packages/mui-material/src/Avatar/Avatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ describe('<Avatar />', () => {

expect(avatar).to.have.class(classes.colorDefault);
});

it('should fallback if children is empty string', () => {
const container = render(<Avatar>{''}</Avatar>).container;
const avatar = container.firstChild;

expect(avatar.firstChild).to.have.attribute('data-testid', 'PersonIcon');
});

it('should fallback if children is false', () => {
const container = render(<Avatar>{false}</Avatar>).container;
const avatar = container.firstChild;

expect(avatar.firstChild).to.have.attribute('data-testid', 'PersonIcon');
});
});

it('should not throw error when ownerState is used in styleOverrides', () => {
Expand Down

0 comments on commit 0ebf32f

Please sign in to comment.