[Grid] Fix "auto" behavior to match natural width of its content #27514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In #11804, support for the
"auto"
value was added to props likexs
,sm
et. al.This prop value causes the MUI grid to work just like Bootstrap's grid "auto" setting most of the time, with a few exceptions:
flex-shrink
remains set to1
, which means the item will not always remain sized based on the "natural" width of its contents like users expect.width: 100%
is still applied when using the"auto"
setting on a nestedGrid
container items (<Grid container item xs="auto" />
), which causes the item to not be sized based on the "natural" width at all.Proposed Solution
Add
flexShrink: 0
andwidth: auto
when a breakpoint size is set to"auto"
so that MUI's grid behaves in a way that is truly "auto" - in the sense that it scales to accommodate the natural width of its content.I realize this constitutes a potentially breaking visual change for consumers, but 5.0 seems like a good time to include it!
Thank you for considering the change!
Preview: https://deploy-preview-27514--material-ui.netlify.app/components/grid/#variable-width-content