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

[Chip] Fix error when theme value is a CSS variable #36654

Merged
merged 2 commits into from
Mar 28, 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
5 changes: 2 additions & 3 deletions packages/mui-material/src/Chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const ChipRoot = styled('div', {
},
})(
({ theme, ownerState }) => {
const deleteIconColor = alpha(theme.palette.text.primary, 0.26);
const textColor =
theme.palette.mode === 'light' ? theme.palette.grey[700] : theme.palette.grey[300];
return {
Expand Down Expand Up @@ -147,14 +146,14 @@ const ChipRoot = styled('div', {
WebkitTapHighlightColor: 'transparent',
color: theme.vars
? `rgba(${theme.vars.palette.text.primaryChannel} / 0.26)`
: deleteIconColor,
: alpha(theme.palette.text.primary, 0.26),
fontSize: 22,
cursor: 'pointer',
margin: '0 5px 0 -6px',
'&:hover': {
color: theme.vars
? `rgba(${theme.vars.palette.text.primaryChannel} / 0.4)`
: alpha(deleteIconColor, 0.4),
: alpha(theme.palette.text.primary, 0.4),
},
...(ownerState.size === 'small' && {
fontSize: 16,
Expand Down
25 changes: 24 additions & 1 deletion packages/mui-material/src/Chip/Chip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
} from 'test/utils';
import Avatar from '@mui/material/Avatar';
import Chip, { chipClasses as classes } from '@mui/material/Chip';
import { ThemeProvider, createTheme, hexToRgb } from '@mui/material/styles';
import {
ThemeProvider,
createTheme,
hexToRgb,
experimental_extendTheme as extendTheme,
} from '@mui/material/styles';
import CheckBox from '../internal/svg-icons/CheckBox';
import defaultTheme from '../styles/defaultTheme';

Expand Down Expand Up @@ -714,4 +719,22 @@ describe('<Chip />', () => {
expect(chip).not.to.have.class(classes.focusVisible);
});
});

describe('CSS vars', () => {
it('should not throw when there is theme value is CSS variable', () => {
const theme = extendTheme();
theme.palette = theme.colorSchemes.light.palette;
theme.palette.text = {
...theme.palette.text,
primary: 'var(--mui-palette-grey-900)',
};
expect(() =>
render(
<ThemeProvider theme={theme}>
<Chip label="Test Chip" />
</ThemeProvider>,
),
).not.to.throw();
});
});
});