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

[Stack] Ensure that marginundefined doesn't occur in styling #33548

Merged
merged 7 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions packages/mui-material/src/Stack/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ export const style = ({ ownerState, theme }) => {
base,
});

if (typeof directionValues === 'object') {
Object.keys(directionValues).forEach((breakpoint, index, breakpoints) => {
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
const directionValue = directionValues[breakpoint];
if (!directionValue) {
const previousDirectionValue =
index > 0 ? directionValues[breakpoints[index - 1]] : 'column';
directionValues[breakpoint] = previousDirectionValue;
}
});
}

const styleFromPropValue = (propValue, breakpoint) => {
return {
'& > :not(style) + :not(style)': {
Expand Down
83 changes: 83 additions & 0 deletions packages/mui-material/src/Stack/Stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,89 @@ describe('<Stack />', () => {
display: 'flex',
});
});

it('should place correct margin direction even though breakpoints are not fully provided', () => {
hbjORbj marked this conversation as resolved.
Show resolved Hide resolved
expect(
style({
ownerState: {
direction: { lg: 'row' },
spacing: { xs: 0, md: 2, xl: 4 },
},
theme,
}),
).to.deep.equal({
[`@media (min-width:${defaultTheme.breakpoints.values.xs}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginTop: '0px',
},
},
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
'& > :not(style) + :not(style)': {
margin: 0,
marginTop: '16px',
},
},
[`@media (min-width:${defaultTheme.breakpoints.values.lg}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginLeft: '16px',
},
flexDirection: 'row',
},
[`@media (min-width:${defaultTheme.breakpoints.values.xl}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginLeft: '32px',
},
},
display: 'flex',
});

expect(
style({
ownerState: {
direction: { lg: 'column', sm: 'row' },
spacing: { md: 2, xl: 4, xs: 0 },
},
theme,
}),
).to.deep.equal({
[`@media (min-width:${defaultTheme.breakpoints.values.xs}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginTop: '0px',
},
},
[`@media (min-width:${defaultTheme.breakpoints.values.sm}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginLeft: '0px',
},
flexDirection: 'row',
},
[`@media (min-width:${defaultTheme.breakpoints.values.md}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginLeft: '16px',
},
},
[`@media (min-width:${defaultTheme.breakpoints.values.lg}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginTop: '16px',
},
flexDirection: 'column',
},
[`@media (min-width:${defaultTheme.breakpoints.values.xl}px)`]: {
'& > :not(style) + :not(style)': {
margin: 0,
marginTop: '32px',
},
},
display: 'flex',
});
});
});

describe('prop: spacing', () => {
Expand Down