Skip to content

[Autocomplete ] Using ownerState is undefined in styleOverrides for Autocomplete on opening the options #43992

@hon2a

Description

@hon2a

Steps to reproduce

Link to live example: CodeSandbox

Steps:

  1. Create a theme containing a style override for the Autocomplete component that makes use of ownerState (reads one of its properties).
  2. Render a simple Autocomplete with that theme.
  3. Click on the Autocomplete to open the list of options.

Current behavior

The application crashes with the following error:

Cannot read properties of undefined (reading '{PROPERTY_NAME}')

because the style override function is called without an ownerState (which should never happen).

Expected behavior

ownerState is always passed to the style override, the list of options opens without any issue.

Context

I'm trying to restyle the component to match the company design system.

Your environment

npx @mui/envinfo
 System:
    OS: macOS 14.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 21.04 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 17.7.1 - ~/.nvm/versions/node/v17.7.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v17.7.1/bin/yarn
    npm: 8.5.2 - ~/.nvm/versions/node/v17.7.1/bin/npm
    pnpm: 7.17.0 - ~/.nvm/versions/node/v17.7.1/bin/pnpm
  Managers:
    Homebrew: 4.2.5 - /usr/local/bin/brew
    pip3: 22.0.4 - /usr/local/bin/pip3
    RubyGems: 3.0.3.1 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 15.0.0 - /usr/bin/gcc
    Git: 2.39.3 - /usr/bin/git
    Clang: 15.0.0 - /usr/bin/clang
    FFmpeg: 6.1.1 - /usr/local/bin/ffmpeg
    Curl: 8.7.1 - /usr/bin/curl
    OpenSSL: 3.2.0 - /usr/local/bin/openssl
  Servers:
    Apache: 2.4.59 - /usr/sbin/apachectl
  IDEs:
    Vim: 9.0 - /usr/bin/vim
    WebStorm: 2024.2.2
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Java: 17.0.4.1 - /Users/jan.konopasek/.sdkman/candidates/java/current/bin/javac
    Perl: 5.34.1 - /usr/bin/perl
    Python3: 3.9.12 - /usr/local/bin/python3
    Ruby: 2.6.10 - /usr/bin/ruby
  Databases:
    SQLite: 3.43.2 - /usr/bin/sqlite3
  Browsers:
    Chrome: 129.0.6668.89
    Safari: 17.6

Tested on Chrome.

Search keywords: Autocomplete ownerState styleOverrides

Metadata

Metadata

Assignees

Labels

scope: autocompleteChanges related to the autocomplete. This includes ComboBox.type: regressionA bug, but worse, it used to behave as expected.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions