mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.89k stars 32.26k forks source link

[TextField] Make fullWidth the default on form element? #37310

Open oliviertassinari opened 1 year ago

oliviertassinari commented 1 year ago

Duplicates

Latest version

Summary 💡

Coming from https://github.com/marmelab/react-admin/issues/8796, it seems it's common for UI libraries to set fullWidth={true} as the default behavior (see benchmark). Maybe we should do the same for MUI's open-source projects.

Screenshot 2023-05-17 at 18 21 35

https://stackblitz.com/edit/react-ts-fbuqu9?file=App.tsx

An alternative option would be to set a consistent min-width CSS property on all the inputs. However, it would be surprising to override, so unlikely to fly.

Examples 🌈

Motivation 🔦

In most of the time, as a developer, you need to set a width to an input element. Sometimes, it's width: 100%, sometimes, it's not, but it's almost never the default value. So maybe we should make this breaking change.

fzaninotto commented 1 year ago

The problem, as I described in https://github.com/marmelab/react-admin/issues/8796, is different: inputs have an inconsistent width by default, which makes the first version of a form always misaligned.

The solution you describe (a 100% width by default) would be a big breaking change. Currently, devs keep the default width when it's large enough to accommodate the content (e.g. for year, zip code, etc), and change it when the possible value is big (e.g. email). Your change would reverse this need for customization, and break all existing form layouts. Also, it would make forms unusable on large screens by default.

I'm +1 with a min-width equal to the current TextField width (computed by the browser using the default size of 20. It would only affect types of field Date and Select, which we do have to change width every time. I don't think a min width is hard to override.

oliviertassinari commented 1 year ago

I don't think a min width is hard to override.

The problem is that developers wouldn't understand why when they set thenwidth property, it's not applied correctly. They would need to know min-width takes precedence over width, they would need to know that the style is applied. IMHO, this is too much requirement. We have a prior art with the Tabs that has a min width and people who struggle to customize it.

I would personally struggle as I wouldn't be able to remember which element has a min width, and because there are others reason why the width might be wrong, I would need to dive into the dev tool => not a great experience.

fzaninotto commented 11 months ago

Whats the status of this discussion?