Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Grid] Fix regression v1 spacing prop with string value #44376

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
4 changes: 2 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: '16px' },
Copy link
Member

@DiegoAndai DiegoAndai Nov 11, 2024

Choose a reason for hiding this comment

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

Shouldn't we keep the sm: 2 test as well instead of replacing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added md: '16px' instead.

},
theme,
}),
Expand All @@ -769,7 +769,7 @@ describe('Material UI <Grid />', () => {
generateColumnGap({
ownerState: {
container: true,
columnSpacing: { xs: 1, sm: 2 },
columnSpacing: { xs: 1, sm: '16px' },
},
theme,
}),
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
Loading