mui / mui/material-ui

[autocomplete] `onChange` not fired for same item consecutively

Open
#29,159 7 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

onChange is not fired when selecting the same item consecutively. A differnt item (or clear) must be selected first.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Curretnly, when selecting the same element consecutively onChange is not fired on the consecutive calls.

Expected Behavior 🤔

Every time an item is selected, onChange something should be called, either onChange (perhaps via a prop that says that an item can be slected multiple times) or perhaps via a dedicated onSelect handler.

Steps to Reproduce 🕹

Steps:

  1. Visit the CodeSandBox
  2. Select an item from the list. Notice how the item is stored in state (via useState)
  3. Clear the state by clicking the "clear selected" button
  4. Select the same item from the autocomplete as selected in step 2

The desired outcome would be for state to be populated again with the item. Instead, onChange is never called and hence state is never re-populated.

Context 🔦

The goal is to allow the same item to be slected multiple times. One use case for this would be when selecting an item from a auto-completed list that can be selected multiple times. Anothe might be re-selecting an item after it was cleared by external state (see link for example).

Your Environment 🌎

MUI v5

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.

Research direction

Start with the linked CodeSandbox reproduction and trace the MUI v5 Autocomplete selection path, focusing on how selecting an item after external state is cleared reaches onChange. Done means selecting the same item again repopulates state instead of being ignored; verify the behavior in the reproduction and add regression coverage if the repository’s existing tests identify a suitable location.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.