Skip to content

Commit 7c0b7e8

Browse files
authored
[material-ui] Skip tonalOffset from setting color channel (#44585)
1 parent 28ac35c commit 7c0b7e8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/mui-material/src/styles/createTheme.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ describe('createTheme', () => {
221221
expect(theme.colorSchemes.dark).to.not.equal(undefined);
222222
});
223223

224+
it('should be able to customize tonal offset', () => {
225+
const theme = createTheme({
226+
cssVariables: true,
227+
palette: {
228+
primary: {
229+
main: green[500],
230+
},
231+
tonalOffset: {
232+
light: 0.1,
233+
dark: 0.9,
234+
},
235+
},
236+
});
237+
expect(theme.palette.primary.main).to.equal('#4caf50');
238+
});
239+
224240
describe('spacing', () => {
225241
it('should provide the default spacing', () => {
226242
const theme = createTheme({ cssVariables: true });

packages/mui-material/src/styles/createThemeWithVars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function setColor(obj, key, defaultValue) {
4040
}
4141

4242
function toRgb(color) {
43-
if (!color || !color.startsWith('hsl')) {
43+
if (typeof color !== 'string' || !color.startsWith('hsl')) {
4444
return color;
4545
}
4646
return hslToRgb(color);
@@ -421,7 +421,7 @@ export default function createThemeWithVars(options = {}, ...args) {
421421

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

424-
if (colors && typeof colors === 'object') {
424+
if (color !== 'tonalOffset' && colors && typeof colors === 'object') {
425425
// Silent the error for custom palettes.
426426
if (colors.main) {
427427
setColor(palette[color], 'mainChannel', safeColorChannel(toRgb(colors.main)));

0 commit comments

Comments
 (0)