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

[material-ui] Revert visual regressions from #42283 #43364

Merged
4 changes: 3 additions & 1 deletion packages/mui-material/src/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const TextFieldRoot = styled(FormControl, {
name: 'MuiTextField',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})({
maxWidth: '100%',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind adding this to TextField vs. FormControl vs. InputBase? I'm not fully familiar with this abstraction hierarchy.

Copy link
Member Author

@ZeeshanTamboli ZeeshanTamboli Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want maxWidth: 100% to be applied directly to the TextField root because it's the component that's immediately impacted by the container's size. While you might consider applying it to FormControl, which TextField inherits, FormControl is primarily responsible for form-related context (like labels and helper text) which Text field also supports and not for the direct sizing or spacing of TextField. Adding maxWidth: 100% to FormControl could create unintended side effects for other form controls.

As for InputBase, it's used by other components like Select. Applying maxWidth: 100% there would impact all components that rely on InputBase, potentially causing layout issues where this behavior isn't needed. And it won't even fix the issue because it is not a direct child of the container.

TextField is a higher-level component that combines InputBase and FormControl, providing a simplified API for common use cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation

});

/**
* The `TextField` is a convenience wrapper for the most common cases (80%).
Expand Down
16 changes: 16 additions & 0 deletions test/regressions/fixtures/TextField/ConstrainedTextField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import TextField from '@mui/material/TextField';

// TextField shouldn't overflow the red bordered container
export default function ConstrainedTextField() {
return (
<div
style={{
width: 100,
border: '1px solid red',
}}
>
<TextField label="Outlined" variant="outlined" />
</div>
);
}