-
-
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] spacing with full width Items / Layout shift #29266
Comments
I am not sure I have the same understanding of the word "Layout shift" as you mentioned. Is it the same as Cumulative Layout Shift or do you mean "padding, margin"? cc @mnajdova @oliviertassinari I am also wondering why the implementation in Grid changed? |
Yes, the wording is probably not quite right - I meant the shifting of certain elements to the left (and top) due to the negative margin. |
I noticed the same thing while migrating to v5 I applied
|
@hbjORbj would you like to take a look at this? |
@mnajdova Will do :) |
+1 - This issue is currently breaking my grid spacing when trying to migrate from v4 to v5. |
Confirmed this issue was introduced in the migration from emotion. It was not an issue in @material-ui/core v5.0.0-alpha.23, and is an issue in v5.0.0-alpha.24 (when the migration to emotion for the Grid was introduced). I used the sandbox above and made some modifications. PR that introduced the change: #24395 |
@kutnickclose Thanks for the update! I left a comment in your PR. |
Please check out the following comment by @kutnickclose ; I think it will be helpful
|
@hbjORbj in my example above (https://codesandbox.io/s/mui-grid-spacing-v5-qs72y?file=/src/App.js) I only used mui v5 components and the issue appears. IMO this is not related to mixing v4 and v5 components. |
I think visually (and without backgrounds), the new padding/margin strategy is not really an issue for my case. I would imagine all the visual specs for the Grid component would pass even with the changed padding/margin strategy because the textfields are correctly placed. That said, the padding/margin change is a breaking change that's not captured in the docs that off-centers the background color of grid items. |
This seems to be a regression of this change: #24332 This is briefly described in grid docs: "Limitation - Negative margin - The spacing between items is implemented with a negative margin. This might lead to unexpected behaviors. For instance, to apply a background color, you need to apply display: flex; to the parent." However, this isn't sufficient and not very informative. I think the quick solution to this issue seems to be manually tweaking padding/margin when using |
I think the Masonry has the same bug as you can see here. The code example is from the mui.com page. |
@Hummel37 No, it is not. You've added a border to If you add a border to |
I just started the migration from v4 => v5 and bumped into this issue as well. I use quite frequently borders on In v4 setting borders would still align the div container centered, but in v5 the container with borders are moving to the left without being centered. |
I have exactly the same issue as @dohomi. Any update on this matter ? This is also breaking all my app grids. |
I'm having the same issue here with a Meteor-React-MUI app that we recently upgraded to MUI5. :) |
@hbjORbj how about we update the migration guide with this one? Looks like a frequent confusion when doing the migration. cc @samuelsycamore as he is currently tweaking the migration guides. |
Exact same issue here. |
@zirkelc Hey, we have released Grid v2 in The doc is not live but you can take a look at https://deploy-preview-33554--material-ui.netlify.app/material-ui/react-grid2/. (Here is the PR for the doc) The usage is like this: import Grid from '@mui/material/Unstable_Grid2'; |
Is there any plan to fix this on v5 stable (Grid v1), or is the recommendation to migrate over to |
Please migrate to Grid2, it will replace the version 1 in the next major release. |
I just encountered the same problem (only top and left padding is added). So, the issue won't be fixed for the old Grid component? The only solution is to use |
The Grid in v5 with spacing=1 adds padding left and top and counters it with a negative margin left and top. However, if the Grid contains only one Item with xs=12 or multiple stacked Items with xs=12, then the left padding and margin should be unnecessary.
Current Behavior 😯
In v5 the Grid adds padding/margin left and causes the layout to shift left even though there is only one Item in the row and no left adjustment necessary:
Expected Behavior 🤔
In v4 the padding/margin was evenly distributed to all sides and therefore no layout shift in case of single full width Items:
The text was updated successfully, but these errors were encountered: