[autocomplete] `onChange` not fired for same item consecutively
Nobody has claimed this yet.
- 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, something should be called, either onChangeonChange (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:
- Visit the CodeSandBox
- Select an item from the list. Notice how the item is stored in state (via
useState) - Clear the state by clicking the "clear selected" button
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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