mui / mui/material-ui

[autocomplete] It triggers onChange when the input value is an empty string

Open
#40,898 9 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

scope: autocomplete type: enhancement
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Steps to reproduce

Link to live example: codesandbox

Steps:

  1. open the codesandbox
  2. follow the 2 reproduction steps provided within the example
Current behavior

When a selected value is cleared, the Autocomplete instantly triggers "onChange"

Expected behavior

Autocomplete should not trigger "onChange"

Context

The behavior is not uniform, because onChange is triggered, when an actual value selection occurs - via blur, keyboard, mouse click on the option, etc.

Your environment

Browser: Firefox 122.0

npx @mui/envinfo
  System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  Binaries:
    Node: 20.9.0 - /usr/local/bin/node
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
  Browsers:
    Chrome: Not Found
  npmPackages:
    @emotion/react: latest => 11.11.3 
    @emotion/styled: latest => 11.11.0 
    @mui/base:  5.0.0-beta.34 
    @mui/core-downloads-tracker:  5.15.7 
    @mui/material: latest => 5.15.7 
    @mui/private-theming:  5.15.7 
    @mui/styled-engine:  5.15.7 
    @mui/system:  5.15.7 
    @mui/types:  7.2.13 
    @mui/utils:  5.15.7 
    @types/react: latest => 18.2.51 
    react: latest => 18.2.0 
    react-dom: latest => 18.2.0 
    typescript: latest => 5.3.3 

Search keywords: autocomplete empty value string onChange

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.