Skip to content

Commit

Permalink
[material-ui][Grid v1] Fix regression spacing prop with string value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Nov 13, 2024
1 parent acaf683 commit 981b033
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/mui-material/src/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function generateRowGap({ theme, ownerState }) {

if (themeSpacing !== '0px') {
return {
marginTop: theme.spacing(-propValue),
marginTop: `-${themeSpacing}`,
[`& > .${gridClasses.item}`]: {
paddingTop: themeSpacing,
},
Expand Down Expand Up @@ -214,7 +214,7 @@ export function generateColumnGap({ theme, ownerState }) {
styles = handleBreakpoints({ theme }, columnSpacingValues, (propValue, breakpoint) => {
const themeSpacing = theme.spacing(propValue);
if (themeSpacing !== '0px') {
const negativeValue = theme.spacing(-propValue);
const negativeValue = `-${themeSpacing}`;
return {
width: `calc(100% + ${themeSpacing})`,
marginLeft: negativeValue,
Expand Down
17 changes: 15 additions & 2 deletions packages/mui-material/src/Grid/Grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ describe('Material UI <Grid />', () => {
generateRowGap({
ownerState: {
container: true,
rowSpacing: { xs: 1, sm: 2 },
rowSpacing: { xs: 1, sm: 2, md: '16px' },
},
theme,
}),
Expand All @@ -763,13 +763,19 @@ describe('Material UI <Grid />', () => {
},
marginTop: '-16px',
},
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
'& > .MuiGrid-item': {
paddingTop: '16px',
},
marginTop: '-16px',
},
});

expect(
generateColumnGap({
ownerState: {
container: true,
columnSpacing: { xs: 1, sm: 2 },
columnSpacing: { xs: 1, sm: 2, md: '16px' },
},
theme,
}),
Expand All @@ -788,6 +794,13 @@ describe('Material UI <Grid />', () => {
marginLeft: '-16px',
width: 'calc(100% + 16px)',
},
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
'& > .MuiGrid-item': {
paddingLeft: '16px',
},
marginLeft: '-16px',
width: 'calc(100% + 16px)',
},
});
});

Expand Down
6 changes: 6 additions & 0 deletions packages/mui-system/src/createTheme/createSpacing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ describe('createSpacing', () => {
expect(spacing(1, 'auto', 2, 3)).to.equal('0.25rem auto 0.5rem 0.75rem');
});

it('should support valid CSS unit', () => {
const spacing = createSpacing();
expect(spacing('16px')).to.equal('16px');
expect(spacing('1rem')).to.equal('1rem');
});

describe('warnings', () => {
it('should warn for wrong input', () => {
expect(() => {
Expand Down

0 comments on commit 981b033

Please sign in to comment.