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

[data grid] DataGrid does not autoresize width correctly when nested with a Drawer style component #15439

Closed
rdougan opened this issue Nov 15, 2024 · 7 comments
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@rdougan
Copy link

rdougan commented Nov 15, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/nice-napier-76g87r?from-embed=&workspaceId=d9cbb423-51f0-4df3-be6d-b113d5e3bb6c
  2. Resize window

Current behavior

The drawer is not visible unless you make the window large enough for DataGrid full width + drawer. If you resize the window smaller, the drawer hides. If you

Expected behavior

Drawer should take up full width of the container.

Context

I first noticed this as my app has a Drawer component with DataGrid's sometimes appearing on screen with it. If I resize, I would like to show the drawer on the left, while showing the full width DataGrid.

Your environment

OSX Chrome & Safari

Search keywords: datagrid width autoresize
Order ID: 86320

@rdougan rdougan added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 15, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Nov 15, 2024
@michelengelen
Copy link
Member

This is a CSS flexbox related problem, not a problem with the data grid. Top force the drawer to a specific width you can use flex: 1, minWidth: 240.

Is this what you are looking for?

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 18, 2024
@michelengelen michelengelen changed the title DataGrid does not autoresize width correctly when nested with a Drawer style component [data grid] DataGrid does not autoresize width correctly when nested with a Drawer style component Nov 18, 2024
@rdougan
Copy link
Author

rdougan commented Nov 18, 2024

@michelengelen I've updated the codesandbox to remove width and add minWidth and flex and the data grid does not follow the size of the container. If you remove the data grid, the container (red) resizes correctly.

https://codesandbox.io/p/sandbox/nice-napier-76g87r?from-embed=&workspaceId=d9cbb423-51f0-4df3-be6d-b113d5e3bb6c

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 18, 2024
@rdougan
Copy link
Author

rdougan commented Nov 21, 2024

I've gotten around it by wrapping the grid in a position: absolute container:

<Box sx={{position: 'relative'}}>
    <Box sx={{inset: 0, position: 'absolute'}}>
        {...grid}
    </Box>
</Box>

I do believe this is still a layout bug with DataGrid.

@rdougan
Copy link
Author

rdougan commented Nov 21, 2024

And another follow up...

The issue can be resolved by adding a minWidth: 0 to the parent container of the data grid.

@michelengelen
Copy link
Member

I tend to disagree. It is not a layout bug of the data grid.

As mentioned before you are encountering a limitation of the flex-box property (and the css grid as well).

A flex item cannot be smaller than the size of its content along the main axis.

To be a bit clearer about this: The flex-child will always try to shrink to fit the size of the content, since min-width: auto is set on it. That's why setting min-width: 0 solves this problem.

Very good answer about this on StackOverflow

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 21, 2024
@michelengelen
Copy link
Member

Its great though that you could fix your problem.
I will close this now! Thanks again for taking the time and opening an issue here!

@michelengelen michelengelen removed the status: waiting for author Issue with insufficient information label Nov 21, 2024
Copy link

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

@rdougan 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

2 participants