Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Avatar] Fix ownerState usage with styleOverrides when fallback is used #36228

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});