Skip to content

Commit 90c4624

Browse files
authored
[material-ui] Do not generate CSS variables for a custom spacing function (#43389)
1 parent 47329ac commit 90c4624

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ function getSpacingVal(spacingInput) {
6464
if (typeof spacingInput === 'number') {
6565
return `${spacingInput}px`;
6666
}
67-
if (typeof spacingInput === 'string') {
68-
return spacingInput;
69-
}
70-
if (typeof spacingInput === 'function') {
71-
return getSpacingVal(spacingInput(1));
72-
}
73-
if (Array.isArray(spacingInput)) {
67+
if (
68+
typeof spacingInput === 'string' ||
69+
typeof spacingInput === 'function' ||
70+
Array.isArray(spacingInput)
71+
) {
7472
return spacingInput;
7573
}
7674
return '8px';

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,16 @@ describe('extendTheme', () => {
495495

496496
it('can be customized as a function', () => {
497497
const theme = extendTheme({ spacing: (factor) => `${0.25 * factor}rem` });
498-
expect(theme.vars.spacing).to.deep.equal('var(--mui-spacing, 0.25rem)');
499-
expect(theme.spacing(2)).to.equal('calc(2 * var(--mui-spacing, 0.25rem))');
498+
expect('spacing' in theme.vars).to.equal(false);
499+
expect(theme.spacing(2)).to.equal('0.5rem');
500+
});
501+
502+
it('a custom function should not be altered', () => {
503+
const theme = extendTheme({
504+
spacing: (val) => (val === 'xs' ? '100px' : val),
505+
});
506+
expect('spacing' in theme.vars).to.equal(false);
507+
expect(theme.spacing('xs')).to.equal('100px');
500508
});
501509
});
502510

0 commit comments

Comments
 (0)