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 container in CardActions no longer take the whole width #44201

Closed
ACayet opened this issue Oct 24, 2024 · 6 comments
Closed

Grid container in CardActions no longer take the whole width #44201

ACayet opened this issue Oct 24, 2024 · 6 comments
Assignees
Labels
component: Grid The React component. status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it v6.x

Comments

@ACayet
Copy link

ACayet commented Oct 24, 2024

Steps to reproduce

Link to live example: (CodeSandbox)

Steps:

  1. Create a CardActions
  2. Create a Grid Container inside the CardActions
  3. Create a Grid Item inside the Grid Container

Current behavior

The Grid container does not take the whole width of the CardActions.

Expected behavior

The Grid container should take the whole width of the CardActions.
In Grid v1 the Grid container had a width css property to 100% (with a calc to take into account margin).

Context

I am trying to migrate from Grid v1 to Grid v2. The code to migrate contains a lot of CardActions containing Grid containers with justifyContent: 'flex-end' that are as a consequence on the left side of the CardActions

Your environment

npx @mui/envinfo
  System:
    OS: Linux 5.15 Linux Mint 21.3 (Virginia)
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 130.0.6723.69

Search keywords: Grid Container CardActions Grid2 Width

@ACayet ACayet added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 24, 2024
@zannager zannager added the component: Grid The React component. label Oct 24, 2024
@ACayet
Copy link
Author

ACayet commented Oct 24, 2024

After some complementary research the same behavior is happenning in AccordionSummary and Toolbar. It might be happening in other components too.

@sai6855
Copy link
Contributor

sai6855 commented Oct 25, 2024

Did some initial investigation, regression seems to stem from absense of width:100% from Grid2 root component. GridV1 has this property but missing in v2.

I've checked migration guide to GridV2 https://mui.com/material-ui/migration/migration-grid-v2/, there is no mention of removal of width:100% property. so i'm expecting this to be an regression instead of expected behaviour.

Added GridV1 demos to OP's sandbox to clearly see differences in behaviour in 2 versions

https://codesandbox.io/p/sandbox/grid-container-in-cardactions-toolbar-and-accordionsummary-no-longer-takes-the-whole-width-forked-2qxwvf?file=%2Fsrc%2FDemo.tsx%3A20%2C6

@ddolcimascolo
Copy link

@siriwatknp @zannager Can you give an update? This is currently blocking our migration and we would like to know if this is something we have to change on our side, or if you'll fix this in core.

Thanks,
David

@siriwatknp
Copy link
Member

@ACayet @ddolcimascolo @sai6855 Grid2 is a rewrite of Grid1. I don't think it's a good practice to set width: 100% by default as that's the default behavior of block element.

In this issue, I'd recommend to use flex: 1 when Grid is in a flex container.

<CardActions>
  <Grid sx={{ flex: 1 }}></CardActions>

Note: Be cautious, it seems like you are overuse the Grid component and make the layout too complex. The Grid layout is useful for organizing layout with media query for a page layout but what you are doing is putting the Grid inside a component which I don't recommend because the Card is a component, not a page. The width varies when it's placed in different containers.

@siriwatknp siriwatknp added status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@ACayet How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@siriwatknp siriwatknp added the v6.x label Nov 4, 2024
@sai6855
Copy link
Contributor

sai6855 commented Nov 4, 2024

@siriwatknp do you think removal of width:100% should be mentioned in migration guide? Maybe it's already present but i couldn't spot it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it v6.x
Projects
None yet
Development

No branches or pull requests

5 participants