-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Unexpected spacing behavior #24272
Comments
I think it works as expected codeSandBox Because spacing is calculated for each item in the respected container. Or your example also works as expected. |
@povilass But if you enter the link of the sanbox that leaves, you will see that it does not work as expected in the example. Update the link because I was wrong |
@vicasas Do you have more details on how it's wrong? |
@oliviertassinari Actually, I don't know if it is an error, but I don't understand why if I copy an example from Grid it doesn't work as in the documentation as it generates horizontal scrolling as shown in the codesanbox link. Given this, I wonder if I am using Grid with correct spacing or not, since in my design it breaks generating horizontal scroll, so I should use any of the solutions indicated in the same documentation, |
I can't reproduce the horizontal scrollbar you are referring to. What browser are you using? Which codesandbox? |
Ok example showed problem bus still you need applied half spacing size to parent https://codesandbox.io/s/new-cache-lrynu like the documentation says. |
As for documentation example fix should be added to root div sandbox. |
@oliviertassinari I am using Chrome in its version 87.0.4280.88 (Official Build) (64 bits), Material UI v4.11.2 and React v17.0.1. To reproduce the "error" what I did was copy and paste the sample code of Basic Grid in a codesanbox, which automatically generates the horizontal scroll. Example https://codesandbox.io/s/frosty-https-j4fzo?file=/src/App.js Another way to reproduce the error is to run the example directly from the documentation by clicking on the codesandbox icon, when it opens it already comes with horizontal scroll @povilass I think the same in the documentation examples should come spacing compensation for the example to work as expected. Or maybe add a more explicit example using Container as parent. |
@vicasas Ok great, thanks. This is exactly why we have documented the limitation of the approach as well as workarounds. At this point, it's probably still too early to use flex-gap as not supported by iOS/Safari. But maybe #9513 will be our salvation. Actually, this diff seems to fix the scrolling issue, could you confirm? diff --git a/packages/material-ui/src/Grid/Grid.js b/packages/material-ui/src/Grid/Grid.js
index fa64775cfc..259596b6e3 100644
--- a/packages/material-ui/src/Grid/Grid.js
+++ b/packages/material-ui/src/Grid/Grid.js
@@ -65,9 +65,9 @@ function generateGrid(globalStyles, theme, breakpoint) {
}
}
-function getOffset(val, div = 1) {
+function getOffset(val) {
const parse = parseFloat(val);
- return `${parse / div}${String(val).replace(String(parse), '') || 'px'}`;
+ return `${parse / 2}${String(val).replace(String(parse), '') || 'px'}`;
}
function generateGutter(theme, breakpoint) {
@@ -81,10 +81,12 @@ function generateGutter(theme, breakpoint) {
}
styles[`spacing-${breakpoint}-${spacing}`] = {
- margin: `-${getOffset(themeSpacing, 2)}`,
+ marginTop: `-${getOffset(themeSpacing)}`,
+ marginLeft: `-${getOffset(themeSpacing)}`,
width: `calc(100% + ${getOffset(themeSpacing)})`,
'& > $item': {
- padding: getOffset(themeSpacing, 2),
+ paddingTop: getOffset(themeSpacing),
+ paddingLeft: getOffset(themeSpacing),
},
};
}); I can't catch regressions. Proof of concept: https://codesandbox.io/s/keen-feather-rdgty. |
@oliviertassinari I tried with that change but the horizontal scrolling still appears. I was comparing how Bootstrap for Grid works, but didn't see more. In the same way, I think it is fine, but the Grid examples of Material UI should be added compensation in the root as indicated in it. For example Basic grid root: {
padding: 8
}
<div className={classes.root}>
<Grid container spacing={3}>
...
</Grid>
</div> ór add this example container: {
paddingTop: 8,
paddingBottom: 8,
}
<Container className={classes.container}>
<Grid container spacing={2}>
<Grid item xs>
...
</Grid>
</Grid>
</Container> |
But it works I applied changes to Grid component and called it Grid2 sandbox. Important When you change property leave just one of them and press codesandbox refresh button. I reproduced issues in Windows 10 Chrome Version 87.0.4280.88 (Official Build) (64-bit) and Microsoft Edge Version 87.0.664.66 (Official build) (64-bit). Maybe it's working if you are using MAC+Chrome. MAC+Chrome not equal to WINDOWS+Chrome. |
@povilass Thanks for the codesandbox. I have tested it in macOS Chome and Windows Chrome latest version, no scrollbar. |
@oliviertassinari Ok this is preview. |
@povilass Ok, so we can reproduce the problem as well as reproduce the solution is working. It sounds like we can move forward with a pull request. |
@oliviertassinari I doubt, is it correct to change the spacing of the 4 axes and leave it to the left and up? In grid layouts, the columns (element) always have their padding on their 4 axes. Personally, I would settle for adding in the Grid examples that overflow padding at the root. |
Hey guys, I fixed that like 2 weeks ago. But I didn't get time to do the PR, may I send the PR and just tag this issue without giving a description? |
@greguintow Can we see the solution? in a codesandbox |
@vicasas Okay, I'll prepare one |
@greguintow Why do we need to add an extra prop? What's wrong with the existing proposed solution? |
@oliviertassinari I've tried to reproduce the same example I used on mine in the proposed solution and didn't work as it should. |
@greguintow Do you have a reproduction? |
I changed on the code sandbox if you want I can add to my demo to compare it. Answering your question about why I decided to go with a prop, it's because I didn't want to cause any breaking change. |
What breaking change are you referring to? Unless #24272 (comment) has a flaw we aren't aware of, we should continue forward with the approach. Adding a new prop isn't OK as a solution. |
@greguintow I keep seeing the same scroll problem |
@vicasas Wow, I really haven't noticed that, I was wondering why there was a blank space on my app haha, okay let me try to fix that. |
@vicasas Could you try https://codesandbox.io/s/keen-feather-rdgty? |
This is I using my example in the proposed solution https://codesandbox.io/s/awesome-dream-21ynb |
@oliviertassinari That approach works, image attached. But I wonder if item should only have left and top padding instead of having them on its 4 axes. The question comes to the fact that other Grids always have padding in the 4 axes🤔 |
I don't think that it matter |
@greguintow It looks like this issue is already existing and different from the scrollbar. |
This comment has been minimized.
This comment has been minimized.
Ignore what you guys saw before on the old section, it was using the latest instead of the next version. |
@oliviertassinari Alright, after a lot of headaches, I could figure out the solution and not just fixing the scrollbar problem, but also the spacing problem. |
@oliviertassinari Let me know if you want to me remove the fullWidth prop and make native support. But please reflect that would be a breaking change, as many users use Grid in a lot of parts of the website and they may have their own fixes, so might be a problem. But native support would probably be better for the bundle as the prop adds around 800 classes because create a class for each spacing for each breakpoint size in each breakpoint. |
Co-authored-by: povilass <povilas810@gmail.com>
Co-authored-by: povilass <povilas810@gmail.com>
@oliviertassinari On PR #24332 there is the same solution without the fullWidth prop that was able to reduce 4x times the ungzipped size of the Grid component comparing to my previous solution. |
Co-authored-by: povilass <povilas810@gmail.com>
Co-authored-by: povilass <povilas810@gmail.com>
Duplicate of #7466 |
Current Behavior 😯
In the Material UI documentation on the Grid component examples, it works fine inside the main container when using spacing
Expected Behavior 🤔
What is expected is that if I copy and paste the same example code to be able to test it will behave in the same way, but this does not work Link to codesandbox
It ends up generating a horizontal scroll.
Some solutions are given, but I don't see these being used in the example.
Container
component as parentSteps to Reproduce 🕹
Steps:
Context 🔦
We were building a Layout for a page and we were in doubt regarding the spacing of the Grid component since we began to have several problems with horizontal scrolling.
Our implementation is
Your Environment 🌎
Material UI v4.11.2
React v17.0.1
`npx @material-ui/envinfo`
The text was updated successfully, but these errors were encountered: