Skip to content

Commit 981b033

Browse files
authored
[material-ui][Grid v1] Fix regression spacing prop with string value (#44376)
1 parent acaf683 commit 981b033

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

packages/mui-material/src/Grid/Grid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export function generateRowGap({ theme, ownerState }) {
170170

171171
if (themeSpacing !== '0px') {
172172
return {
173-
marginTop: theme.spacing(-propValue),
173+
marginTop: `-${themeSpacing}`,
174174
[`& > .${gridClasses.item}`]: {
175175
paddingTop: themeSpacing,
176176
},
@@ -214,7 +214,7 @@ export function generateColumnGap({ theme, ownerState }) {
214214
styles = handleBreakpoints({ theme }, columnSpacingValues, (propValue, breakpoint) => {
215215
const themeSpacing = theme.spacing(propValue);
216216
if (themeSpacing !== '0px') {
217-
const negativeValue = theme.spacing(-propValue);
217+
const negativeValue = `-${themeSpacing}`;
218218
return {
219219
width: `calc(100% + ${themeSpacing})`,
220220
marginLeft: negativeValue,

packages/mui-material/src/Grid/Grid.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ describe('Material UI <Grid />', () => {
746746
generateRowGap({
747747
ownerState: {
748748
container: true,
749-
rowSpacing: { xs: 1, sm: 2 },
749+
rowSpacing: { xs: 1, sm: 2, md: '16px' },
750750
},
751751
theme,
752752
}),
@@ -763,13 +763,19 @@ describe('Material UI <Grid />', () => {
763763
},
764764
marginTop: '-16px',
765765
},
766+
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
767+
'& > .MuiGrid-item': {
768+
paddingTop: '16px',
769+
},
770+
marginTop: '-16px',
771+
},
766772
});
767773

768774
expect(
769775
generateColumnGap({
770776
ownerState: {
771777
container: true,
772-
columnSpacing: { xs: 1, sm: 2 },
778+
columnSpacing: { xs: 1, sm: 2, md: '16px' },
773779
},
774780
theme,
775781
}),
@@ -788,6 +794,13 @@ describe('Material UI <Grid />', () => {
788794
marginLeft: '-16px',
789795
width: 'calc(100% + 16px)',
790796
},
797+
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
798+
'& > .MuiGrid-item': {
799+
paddingLeft: '16px',
800+
},
801+
marginLeft: '-16px',
802+
width: 'calc(100% + 16px)',
803+
},
791804
});
792805
});
793806

packages/mui-system/src/createTheme/createSpacing.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ describe('createSpacing', () => {
5151
expect(spacing(1, 'auto', 2, 3)).to.equal('0.25rem auto 0.5rem 0.75rem');
5252
});
5353

54+
it('should support valid CSS unit', () => {
55+
const spacing = createSpacing();
56+
expect(spacing('16px')).to.equal('16px');
57+
expect(spacing('1rem')).to.equal('1rem');
58+
});
59+
5460
describe('warnings', () => {
5561
it('should warn for wrong input', () => {
5662
expect(() => {

0 commit comments

Comments
 (0)