Skip to content

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

Closed as not planned
@yogeshkrishnani-alation

Description

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

Metadata

Metadata

Assignees

Labels

component: autocompleteThis is the name of the generic UI component, not the React module!duplicateThis issue or pull request already exists

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions