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

Autocomplete component breaks when slotProps are provided for textfield override in theme #44194

Closed
yogeshkrishnani-alation opened this issue Oct 23, 2024 · 5 comments
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@yogeshkrishnani-alation
Copy link

yogeshkrishnani-alation commented Oct 23, 2024

Steps to reproduce

Link to live example: https://stackblitz.com/edit/vitejs-vite-6rklm8?file=src%2FApp.jsx

Steps:

  1. Create a theme and modify the MuiTextField default props
const theme = createTheme({
  components: {
    MuiTextField: {
      defaultProps: {
        slotProps: {
          input: {
            disableUnderline: true,
          },
        },
        variant: 'outlined',
      },
    },
  },
});
  1. Create an autocomplete component and wrap it inside the created theme
<ThemeProvider theme={theme}>
  <div>
    <Autocomplete
      disablePortal={true}
      options={[
        { label: 'The Shawshank Redemption', year: 1994 },
        { label: 'The Godfather', year: 1972 },
        { label: 'The Godfather: Part II', year: 1974 },
        { label: 'The Dark Knight', year: 2008 },
        { label: '12 Angry Men', year: 1957 },
        { label: "Schindler's List", year: 1993 },
        { label: 'Pulp Fiction', year: 1994 },
      ]}
      renderInput={(params) => <TextField {...params} label="Movie" />}
      sx={{ width: 300 }}
    />
  </div>
</ThemeProvider>

Current behavior

Autocomplete component is not working

Expected behavior

Autocomplete component should work as expected

Context

If we replace slotProps with InputProps, autocomplete is working as expected. However, that's not ideal, as InputProps is deprecated and will be removed in v7.

Your environment

npx @mui/envinfo
  System:
    OS: Linux 5.0 undefined
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 130.0.6723.59
  npmPackages:
    @emotion/react: ^11.13.3 => 11.13.3 
    @emotion/styled: ^11.13.0 => 11.13.0 
    @mui/core-downloads-tracker:  6.1.5 
    @mui/material: ^6.1.5 => 6.1.5 
    @mui/private-theming:  6.1.5 
    @mui/styled-engine:  6.1.5 
    @mui/system:  6.1.5 
    @mui/types:  7.2.18 
    @mui/utils:  6.1.5 
    @types/react: ^18.3.11 => 18.3.11 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.1 => 18.3.1 

Search keywords: autocomplete, slotProps, textfield, override, theme

@yogeshkrishnani-alation yogeshkrishnani-alation added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 23, 2024
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Oct 23, 2024
@mj12albert
Copy link
Member

@yogeshkrishnani-alation disableUnderline is only for the 'filled' variant of TextField, not 'outlined'
This theme should work:

const theme = createTheme({
  palette: {
    primary: {
      main: purple[500],
    },
    secondary: {
      main: green[500],
    },
  },
  components: {
    MuiTextField: {
      defaultProps: {
        disableUnderline: true,
        variant: 'filled',
      },
    },
  },
});

Here's a working sandbox: https://stackblitz.com/edit/vitejs-vite-fygb6l?file=src%2FApp.jsx

@mj12albert
Copy link
Member

Duplicate of #44145

@mj12albert mj12albert marked this as a duplicate of #44145 Oct 23, 2024
@github-actions github-actions bot added duplicate This issue or pull request already exists and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 23, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@yogeshkrishnani-alation
Copy link
Author

@mj12albert Thanks for the quick response! I understand now that disableUnderline is only applicable to the 'filled' variant and not 'outlined'. However, I noticed in the example you provided that you didn’t use slotProps to pass disableUnderline. Is there a particular reason for this approach?

When I try to pass disableUnderline through slotProps, the Autocomplete component still breaks. I've shared a sandbox link here for reference: https://stackblitz.com/edit/vitejs-vite-6rklm8?file=src%2FApp.jsx.

Previously, we used InputProps to pass disableUnderline, but during the MUI upgrade from v5 to v6, it was replaced by slotProps.input. The issue I’m facing is that when the Autocomplete breaks, there’s no MUI-specific error or stack trace to indicate why it’s failing. This makes it hard to troubleshoot the issue, especially if it’s related to using disableUnderline with an incompatible variant.

Do you think there’s room for improvement in how MUI handles overrides or provides error feedback in cases like this?

@mj12albert
Copy link
Member

mj12albert commented Oct 24, 2024

you didn’t use slotProps to pass disableUnderline. Is there a particular reason for this approach?

@yogeshkrishnani-alation It's not supported yet 😓 see #43606

@yogeshkrishnani-alation
Copy link
Author

@mj12albert I would describe it as being supported since it's part of the official documentation and the mui version upgrade/migration script, but not fully functional due to some existing open issues like #43606.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants