Skip to content

Commit

Permalink
[Avatar] Fix ownerState usage with styleOverrides when fallback is us…
Browse files Browse the repository at this point in the history
…ed (#36228)
  • Loading branch information
sai6855 committed Feb 17, 2023
1 parent 74b2721 commit 358cd5d
Show file tree
Hide file tree
Showing 2 changed files with 26 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 @@ -176,7 +176,7 @@ const Avatar = React.forwardRef(function Avatar(inProps, ref) {
} else if (hasImg && alt) {
children = alt[0];
} else {
children = <AvatarFallback className={classes.fallback} />;
children = <AvatarFallback ownerState={ownerState} className={classes.fallback} />;
}

return (
Expand Down
25 changes: 25 additions & 0 deletions packages/mui-material/src/Avatar/Avatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { createRenderer, fireEvent, describeConformance } from 'test/utils';
import { spy } from 'sinon';
import Avatar, { avatarClasses as classes } from '@mui/material/Avatar';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import CancelIcon from '../internal/svg-icons/Cancel';

describe('<Avatar />', () => {
Expand Down Expand Up @@ -212,4 +213,28 @@ describe('<Avatar />', () => {
expect(avatar).to.have.class(classes.colorDefault);
});
});

it('should not throw error when ownerState is used in styleOverrides', () => {
const theme = createTheme({
components: {
MuiAvatar: {
styleOverrides: {
root: ({ ownerState }) => ({
...(ownerState.variant === 'rounded' && {
color: 'red',
}),
}),
},
},
},
});

expect(() =>
render(
<ThemeProvider theme={theme}>
<Avatar variant="rounded" />
</ThemeProvider>,
),
).not.to.throw();
});
});

0 comments on commit 358cd5d

Please sign in to comment.