Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoComplete] onChange being called when value is duplicated #30150

Closed
2 tasks done
ryjogo opened this issue Dec 11, 2021 · 3 comments · Fixed by #30374
Closed
2 tasks done

[AutoComplete] onChange being called when value is duplicated #30150

ryjogo opened this issue Dec 11, 2021 · 3 comments · Fixed by #30374
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@ryjogo
Copy link

ryjogo commented Dec 11, 2021

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

According to the documentation:

Callback fired when the value changes.

However, it seems that when the value is a duplicate - the onChange hook is ran.

Expected behavior 🤔

onChange should not run, as the value has not changed?

Steps to reproduce 🕹

https://codesandbox.io/s/vibrant-surf-ztbsl

Steps:

  1. send a freesolo item, i.e. "hello" press enter
  2. send a second freesolo item, "hello" press enter
  3. observe the chip is not added, however in the console the onChange event happens..

Context 🔦

I would like to send my chip updates as tags to a RESTful API:

switch (reason) {
  case 'createOption':
  case 'selectOption':
    console.log('POST: ' + detail.option);
    break;
  case 'removeOption':
    console.log('DELETE: ' + detail.option);
    break;
  default:
    console.log(reason);
    break;
}

However, currently it will produce POST requests upon a duplicate item. I can of course, handle this in the backend - but as far as i can see in the docs it states onChange will fire when changed.

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@ryjogo ryjogo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 11, 2021
@michaldudak michaldudak added bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 17, 2021
@michaldudak
Copy link
Member

Thanks for the report. I agree that onChange should not be called in this case.

@alisasanib
Copy link
Contributor

Hi! I would like to work on this issue

@michaldudak
Copy link
Member

@alisasanib go ahead, it's all yours!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants