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][Select] Not working with the styled input prop: Prop className did not match #40987

Closed
RiccardoRomagnoli opened this issue Feb 7, 2024 · 1 comment
Labels
component: FormControl The React component component: select This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material

Comments

@RiccardoRomagnoli
Copy link

RiccardoRomagnoli commented Feb 7, 2024

Steps to reproduce

Link to live example

Current behavior

When using a styled component for the input prop of the component Select:

  • Styled does not get applied
  • SSR warning gets thrown: Prop className did not match. Server: "MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary css-f85pof-MuiInputBase-root-MuiOutlinedInput-root" Client: "MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-formControl css-f85pof-MuiInputBase-root-MuiOutlinedInput-root"

Expected behavior

The Select styles are the one in the styled component, if you uncomment the styles from the globals.css they get applied.

Context

I'm trying to change the styles of the input component of the Select

Your environment

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 18.17.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD    
    pnpm: Not Found
  Browsers:
    Chrome: 121.0.6167.140
    Edge: Chromium (121.0.2277.98)
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.1 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/base:  5.0.0-beta.7 
    @mui/core-downloads-tracker:  5.14.0 
    @mui/icons-material: ^5.14.0 => 5.14.0
    @mui/lab: ^5.0.0-alpha.137 => 5.0.0-alpha.137
    @mui/material: ^5.14.0 => 5.14.0
    @mui/material-nextjs: ^5.15.6 => 5.15.6
    @mui/private-theming:  5.13.7
    @mui/styled-engine:  5.13.2
    @mui/system:  5.14.1
    @mui/types:  7.2.4
    @mui/utils:  5.14.1
    @types/react: ^18.2.6 => 18.2.15
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    typescript: ^5.0.4 => 5.1.6

Search keywords: Select styled input

@RiccardoRomagnoli RiccardoRomagnoli added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 7, 2024
@danilo-leal danilo-leal changed the title Select with styled input prop not working: Prop className did not match [material-ui][Select] Not working with the styled input prop: Prop className did not match Feb 7, 2024
@danilo-leal danilo-leal added component: select This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Feb 7, 2024
@ZeeshanTamboli
Copy link
Member

Styled does not get applied

@RiccardoRomagnoli Since you're styling the label of the Select, which is rendered via the InputLabel component, you should use the styled API on the FormControl component. The label is outside of the OutlinedInput, so it's not targeted there. Here's the updated CodeSandbox. Additionally, you won't need the custom input prop.

SSR warning gets thrown: Prop className did not match. Server: "MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary css-f85pof-MuiInputBase-root-MuiOutlinedInput-root" Client: "MuiInputBase-root MuiOutlinedInput-root MuiInputBase-colorPrimary MuiInputBase-formControl css-f85pof-MuiInputBase-root-MuiOutlinedInput-root"

I don't see the warning in your provided CodeSandbox, however, it looks related to #27512.

@ZeeshanTamboli ZeeshanTamboli added component: FormControl The React component and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: FormControl The React component component: select This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

4 participants