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][TextField] The override for MuiTextField does not work after changing from version 5.15.21 to 5.16.4 #42983

Closed
donCapybaradev opened this issue Jul 17, 2024 · 11 comments
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material status: waiting for author Issue with insufficient information

Comments

@donCapybaradev
Copy link

donCapybaradev commented Jul 17, 2024

Steps to reproduce

Apply an override of the variant to standard in the latest version.

Current behavior

The override for MuiTextField does not work after changing from version 5.15.21 to 5.16.4.

This is the code I use for that part of the override for this component:


MuiTextField: {
  defaultProps: {
    variant: 'standard',
  },
  styleOverrides: {
    root: {
      '& .MuiInputBase-root': {
        color: 'red',
        backgroundColor: 'blue',
      },
    },
  },
},


The styleOverrides is used to validate that the color change works, but the standard variant is not applied.

Expected behavior

The standard format is expected to be applied to the MuiTextField components.

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: 5.16.4

@donCapybaradev donCapybaradev added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 17, 2024
@donCapybaradev donCapybaradev changed the title The override for MuiTextField does not work after changing from version 5.16.0 to 5.16.4 The override for MuiTextField does not work after changing from version 5.15.21 to 5.16.4 Jul 17, 2024
@sohail9744
Copy link

@donCapybaradev what i understand from your issue if it's not the solution for you, please provide a video it would be helpful to understand

There might be a regression or change in how the variant default is handled in version 5.16.4. To work around this issue, you can explicitly set the variant when using the TextField component or use a custom wrapper component to ensure the standard variant is applied.

import { createTheme, ThemeProvider } from '@mui/material/styles';
import TextField from '@mui/material/TextField';

const theme = createTheme({
  components: {
    MuiTextField: {
      styleOverrides: {
        root: {
          '& .MuiInputBase-root': {
            color: 'red',
            // backgroundColor: 'blue',
          },
        },
      },
    },
  },
});

// ;) custom wrapper
function StandardTextField(props) {
  return <TextField variant="standard" {...props} />;
}

function App() {
  return (
    <ThemeProvider theme={theme}>
      <StandardTextField label="Test" />
    </ThemeProvider>
  );
}

export default App;

@sohail9744
Copy link

The standard format is applying on my MuiText field it's working for me in the version of 5.16.4 check your theming might be there you are doing some mistake.

@donCapybaradev
Copy link
Author

@sohail9744 Yes, I considered that as a solution, but using Overrides to apply the standard variant is simpler due to the frequency with which I use this component in my system. It seems strange that the Overrides for this particular component don't work, and this issue occurred right after updating to the new version.

@Twipped
Copy link

Twipped commented Jul 17, 2024

We're also noticing a change in styleOverrides variants behavior between 5.15.21 and 5.16.0. I haven't isolated an exact cause yet, but I suspect it has something to do with the rewrite of getInitColorSchemeScript. The css vars that we inject via ScopedCssBaseline are just plain missing.

Unfortunately I don't have a reproduction case I can share, yet.

Edit: I was looking at the wrong code block, the variables are defined in variants, styleOverrides just makes use of them. The usage is present on the page, but the css from the variants isn't. In our case, this is on the Card component, but it's probably connected.

@brijeshb42 brijeshb42 added package: material-ui Specific to @mui/material component: text field This is the name of the generic UI component, not the React module! labels Jul 18, 2024
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Jul 19, 2024

A reproduction that it works in 5.16.4: https://stackblitz.com/edit/vitejs-vite-dmucqd?file=package.json&terminal=dev. Can somebody a reproduction where it does not work?

@ZeeshanTamboli ZeeshanTamboli 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 Jul 19, 2024
@ZeeshanTamboli ZeeshanTamboli changed the title The override for MuiTextField does not work after changing from version 5.15.21 to 5.16.4 [material-ui][TextField] The override for MuiTextField does not work after changing from version 5.15.21 to 5.16.4 Jul 19, 2024
Copy link

Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

@nuarhu
Copy link

nuarhu commented Aug 9, 2024

@ZeeshanTamboli the Stackblizt that you have linked is using mui/material in version 5.15.21 - that was still working.

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli the Stackblizt that you have linked is using mui/material in version 5.15.21 - that was still working.

My bad. Updated the StackBlitz link above, but it still works in 5.16.4.

@grantbdev
Copy link

@ZeeshanTamboli I am experiencing similar issues as the users above and I believe related to #42892, but let me know if you prefer a new issue to be open.

I believe the behavior of default props from themes changed in MUI 5.16.0 as a result of #42820 in an unintentional way that is causing the default props defined in the theme not to be used under certain circumstances: using @mui/icons-material and esbuild.


Here is a devbox with the code working as expected with MUI 5.15.21: https://codesandbox.io/p/devbox/reverent-dawn-qqqgnt?file=%2Fsrc%2Findex.jsx%3A12%2C25

The theme's default props for the text field makes the input full-width and adds normal margin:
Screenshot 2024-09-02 at 7 05 04 PM


Here is a devbox with the versions bumped to MUI 5.16.7: https://codesandbox.io/p/devbox/reproduction2-not-working-with-icon-forked-rvr4ck?workspaceId=c2ade9f2-c903-41e5-b3b0-05ae3b29e582

The default props are not passed for the text field:
Screenshot 2024-09-02 at 7 07 09 PM


Here is a devbox with MUI 5.16.7, but no import used from @mui/icons-material: https://codesandbox.io/p/devbox/hardcore-lewin-tjvy3x?file=%2Fsrc%2Findex.jsx%3A9%2C20

The default props are passed, which indicates that something from the icon import is messing with the code in some way:
Screenshot 2024-09-02 at 7 10 27 PM


I tried altering the other variables, React version, emotion instead of styled components, but the only thing that seemed to make a difference besides the icon import was using something other than esbuild.

@ZeeshanTamboli
Copy link
Member

@grantbdev Thanks for the detailed reproductions. Yes, it would be better to create a new issue. Also, this is only related to v5. It works with v6 whether you have the icon import or not: https://codesandbox.io/p/devbox/reproduction2-not-working-with-icon-forked-qt975l?workspaceId=92b035ba-df9d-45a7-90b6-6b416aafd4ba.

@grantbdev
Copy link

@ZeeshanTamboli Thanks for that note. Today I tested the upgrade to v6 and it did not reproduce this issue. Unfortunately, I'm not able to upgrade yet due to other problems I encountered that I think might be fixed in an upcoming release. However now I know I can jump straight to v6 (hopefully next month) without having to worry about this specific problem, so I will not open a new issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

8 participants