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] Fix CSS selector #37525

Merged
merged 2 commits into from
Jul 29, 2023
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
124 changes: 93 additions & 31 deletions packages/mui-system/src/Stack/Stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@ describe('<Stack />', () => {
).to.deep.equal({
'@media (min-width:0px)': {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '8px',
},
'& > :not(style):not(style)': {
margin: 0,
},
flexDirection: 'column',
},
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginLeft: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
flexDirection: 'row',
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginLeft: '32px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
display: 'flex',
flexDirection: 'column',
Expand All @@ -65,16 +71,20 @@ describe('<Stack />', () => {
).to.deep.equal({
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
flexDirection: 'column',
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginLeft: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
flexDirection: 'row',
},
display: 'flex',
Expand All @@ -94,15 +104,19 @@ describe('<Stack />', () => {
).to.deep.equal({
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '32px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
display: 'flex',
flexDirection: 'column',
Expand All @@ -121,21 +135,27 @@ describe('<Stack />', () => {
).to.deep.equal({
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '0px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
[`@media (min-width:${theme.breakpoints.values.lg}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '32px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
display: 'flex',
flexDirection: 'column',
Expand All @@ -153,9 +173,11 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
'& > :not(style) ~ :not(style)': {
margin: 0,
marginLeft: '24px',
},
'& > :not(style):not(style)': {
margin: 0,
},
display: 'flex',
flexDirection: 'row',
});
Expand All @@ -173,16 +195,20 @@ describe('<Stack />', () => {
).to.deep.equal({
'@media (min-width:0px)': {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '8px',
},
'& > :not(style):not(style)': {
margin: 0,
},
flexDirection: 'column',
},
[`@media (min-width:${theme.breakpoints.values.lg}px)`]: {
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '16px',
},
'& > :not(style):not(style)': {
margin: 0,
},
},
display: 'flex',
flexDirection: 'column',
Expand All @@ -201,9 +227,11 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
'& > :not(style) ~ :not(style)': {
margin: 0,
marginBottom: '8px',
},
'& > :not(style):not(style)': {
margin: 0,
},
display: 'flex',
flexDirection: 'column-reverse',
});
Expand All @@ -220,22 +248,28 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
'@media (min-width:0px)': {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '8px',
},
flexDirection: 'column',
},
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '16px',
},
flexDirection: 'row',
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '24px',
},
},
Expand Down Expand Up @@ -272,27 +306,35 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
[`@media (min-width:${theme.breakpoints.values.xs}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '0px',
},
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '16px',
},
},
[`@media (min-width:${theme.breakpoints.values.lg}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '16px',
},
flexDirection: 'row',
},
[`@media (min-width:${theme.breakpoints.values.xl}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '32px',
},
},
Expand All @@ -310,34 +352,44 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
[`@media (min-width:${theme.breakpoints.values.xs}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '0px',
},
},
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '0px',
},
flexDirection: 'row',
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginLeft: '16px',
},
},
[`@media (min-width:${theme.breakpoints.values.lg}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '16px',
},
flexDirection: 'column',
},
[`@media (min-width:${theme.breakpoints.values.xl}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '32px',
},
},
Expand All @@ -359,20 +411,26 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
'@media (min-width:0px)': {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '8px',
},
},
[`@media (min-width:${theme.breakpoints.values.sm}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '16px',
},
},
[`@media (min-width:${theme.breakpoints.values.md}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '24px',
},
},
Expand Down Expand Up @@ -404,9 +462,11 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
'& > :not(style) ~ :not(style)': {
margin: 0,
marginTop: '32px',
},
'& > :not(style):not(style)': {
margin: 0,
},
display: 'flex',
flexDirection: 'column',
});
Expand Down Expand Up @@ -435,8 +495,10 @@ describe('<Stack />', () => {
}),
).to.deep.equal({
[`@media (min-width:${customTheme.breakpoints.values.small}px)`]: {
'& > :not(style) ~ :not(style)': {
'& > :not(style):not(style)': {
margin: 0,
},
'& > :not(style) ~ :not(style)': {
marginTop: '32px',
},
},
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-system/src/Stack/createStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ export const style = ({ ownerState, theme }: StyleFunctionProps) => {
return { gap: getValue(transformer, propValue) };
}
return {
'& > :not(style) ~ :not(style)': {
// The useFlexGap={false} implement relies on each child to give up control of the margin.
// We need to reset the margin to avoid double spacing.
Comment on lines +138 to +139
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The useFlexGap={false} implement relies on each child to give up control of the margin.
// We need to reset the margin to avoid double spacing.
// The useFlexGap={false} implementation relies on each child to give up control of the margin.
// We need to reset the margin to avoid double spacing.
// TODO: remove this reset https://github.com/mui/material-ui/issues/28035#issuecomment-1615855826

'& > :not(style):not(style)': {
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
margin: 0,
Copy link
Member

@oliviertassinari oliviertassinari Jul 1, 2023

Choose a reason for hiding this comment

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

We could consider the path to not reset the margin in the first place. It would get closer to useFlexGap={true}'s behavior. I have made this proposal in #28035 (comment).

Suggested change
margin: 0,

The problem is that it's a bit more breaking change than the current changes in this PR, so maybe for v6.

},
'& > :not(style) ~ :not(style)': {
[`margin${getSideFromDirection(
breakpoint ? directionValues[breakpoint] : ownerState.direction,
)}`]: getValue(transformer, propValue),
Expand Down