-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Fix hardcoded TextField size prop #9554
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree too since RA's defaultTheme
sets the MuiTextField
defaultProps
to "small
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right code, thanks! However we need to document this change in the upgrade guide. People with a custom theme will see their inputs size change from small to medium, and this is a regression. We also need to document the custom size somewhere in the Inputs documentation.
We usually put the doc and the code in the same PR, would you mind doing these changes in your PR?
Yeah, I can give it a spin later today! |
…heme Updated docs
Okay, I've updated the documentation, and took the liberty of changing the theme configurations to use For example, using deepmerge, you can easily override just the It's a "big breaking change" (old way would still work). I hope this is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're still missing a section in the v5 upgrade guide for people with a custom theme in v4.
main: '#2196f3', | ||
dark: '#0069c0', | ||
contrastText: '#fff', | ||
export const defaultLightTheme: RaThemeOptions = createTheme( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't call createTheme
here as our theme provider does it, too.
dark: '#0069c0', | ||
contrastText: '#fff', | ||
export const defaultLightTheme: RaThemeOptions = createTheme( | ||
deepmerge(defaultThemeInvariants, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the deepMerge here, as we know what we're merging. I prefer the old version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepMerge here allows new changes to be made more easily in the future, in my opinion. Imagine, as a crude example, you want the darkTheme to have their textfields with a width of 50% by default.
To do this change without using deepmerge:
const defaultDarkTheme: RaThemeOptions = {
...defaultThemeInvariants,
palette: {
mode: 'dark',
primary: {
main: '#90caf9',
},
background: {
default: '#313131',
},
},
+ components: {
+ ...defaultThemeInvariants.components,
+ MuiTextField: {
+ ...defaultThemeInvariants.components.MuiTextField,
+ defaultProps: {
+ ...defaultThemeInvariants.components.MuiTextField.defaultProps,
+ sx: {
/*
If you later add a default sx to defaultThemeInvariants,
you need to remember to come here and add the following line:
+ ...defaultThemeInvariants.components.MuiTextField.defaultProps.sx,
*/
+ width: "50%"
+ }
+ },
+ },
+ }
}
With deepmerge:
export const defaultDarkTheme: RaThemeOptions = deepmerge(defaultThemeInvariants, {
palette: {
mode: 'dark',
primary: {
main: '#90caf9',
},
background: {
default: '#313131',
},
},
+ components: {
+ MuiTextField: {
+ defaultProps: {
+ sx: {
+ width: "50%"
+ }
+ }
+ }
+ }
})
);
The retro-active update mentioned in the comment being specially worrying in my opinion.
Alright, I'll give the review a spin, hopefully monday. |
Removed legacy ToggleTheme and useTheme code
Okay, I've added the useTheme changes to the migration guide; I also went ahead and removed the legacy code on Regarding this:
I left a response to your comment; waiting on a reply to know if I should revert the changes there or keep them. |
BUMPing this since I'm still awaiting on a reply from @fzaninotto to know if it needs more changes or is ready 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting close to the merge!
Removed deprecated code from ToggleThemeButton
Fixed the latest comments and the merge conflits |
Thanks a lot! |
This fixes the issue the issue with the TextField size prop not being override-able by theme. RA's default theme actually already sets the MuiTextField size prop default value as "small", so it's redundant to have it here.
However, in a possibly unrelated note, it may be benefitial to extend RA's documentation and themeing options with a re-export of MUI's
createTheme
function, that allows the deep-merging of themes, or maybe recommendlodash.merge
to set up themes.With this PR, overriding the theme's TextField variant as per RA's docs will result in the
size="small"
property to be lost.Closes #9546