Skip to content
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
15 changes: 15 additions & 0 deletions packages/mui-material/src/styles/createTheme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,21 @@ describe('createTheme', () => {
'color-mix(in oklch, hsl(0 0% 100%), #000 20%)',
);
});

it('should not warn about channel token if nativeColor is used and custom palette colors are provided', () => {
expect(() =>
createTheme({
cssVariables: { nativeColor: true },
palette: {
divider: 'var(--mui-palette-divider)',
background: {
default: 'var(--mui-palette-background-default)',
paper: 'var(--mui-palette-background-paper)',
},
},
}),
).not.toWarnDev();
});
});

// Skip WebKit and firefox because they have a slightly different value
Expand Down
17 changes: 9 additions & 8 deletions packages/mui-material/src/styles/createThemeWithVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,23 +898,24 @@ export default function createThemeWithVars(options = {}, ...args) {
);
}

// MUI X - DataGrid needs this token.
setColorChannel(palette.background, 'default');
if (!nativeColor) {
setColorChannel(palette.background, 'default');

// added for consistency with the `background.default` token
setColorChannel(palette.background, 'paper');
// added for consistency with the `background.default` token
setColorChannel(palette.background, 'paper');

setColorChannel(palette.common, 'background');
setColorChannel(palette.common, 'onBackground');
setColorChannel(palette.common, 'background');
setColorChannel(palette.common, 'onBackground');

setColorChannel(palette, 'divider');
setColorChannel(palette, 'divider');
}

Object.keys(palette).forEach((color) => {
const colors = palette[color];

// The default palettes (primary, secondary, error, info, success, and warning) errors are handled by the above `createTheme(...)`.

if (color !== 'tonalOffset' && colors && typeof colors === 'object') {
if (color !== 'tonalOffset' && !nativeColor && colors && typeof colors === 'object') {
// Silent the error for custom palettes.
if (colors.main) {
setColor(palette[color], 'mainChannel', safeColorChannel(toRgb(colors.main)));
Expand Down
Loading