Skip to content
Open
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 @@ -781,5 +781,20 @@ 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();
});
});
});
19 changes: 11 additions & 8 deletions packages/mui-material/src/styles/createThemeWithVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,23 +550,26 @@ export default function createThemeWithVars(options = {}, ...args) {
setColor(palette.Tooltip, 'bg', colorMix(safeAlpha, palette.grey[700], 0.92));
}

// MUI X - DataGrid needs this token.
setColorChannel(palette.background, 'default');
// Do not create channel tokens when nativeColor is used.
if (!nativeColor) {
// MUI X - DataGrid needs this token.
setColorChannel(palette.background, 'default');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not sure how to handle this since MUI X is using some channel tokens.
https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/material/variables.ts#L31-L39

Copy link
Member Author

@ZeeshanTamboli ZeeshanTamboli Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still generate the channel tokens when nativeColor is not used, right? So that means it will generate for MUI X, won't it?


// 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