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] allow clearing the value also programmatically #37738

Open
2 tasks done
jaritheman opened this issue Jun 27, 2023 · 6 comments
Open
2 tasks done

[Autocomplete] allow clearing the value also programmatically #37738

jaritheman opened this issue Jun 27, 2023 · 6 comments
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature waiting for 👍 Waiting for upvotes

Comments

@jaritheman
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

When the options for Autocomplete are likely to change over time, it means that a situation is likely that currently selected value is no longer available in the options. In such case Autocomplete starts spamming a "The value provided to Autocomplete is invalid." warning to the console.

It would be quite important to be able to handle the situation and for example then clear the value programmatically (=essentially call the same function that the manual clear button calls). Currently this does not seem to be possible.

Examples 🌈

SO thread about it with some code: https://stackoverflow.com/questions/76515033/mui-autocomplete-how-to-clear-value-when-options-change

Motivation 🔦

Better interface to handle an edge case

@jaritheman jaritheman added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 27, 2023
@michaldudak michaldudak self-assigned this Jun 27, 2023
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Jun 28, 2023
@michaldudak
Copy link
Member

Yes, I think including something like this could be a good thing. Ideally, the autocomplete would use a reducer internally and we could expose a dispatch function that would allow you to trigger different actions (similarly to how Base UI compound components work), but we're not there yet.

cc @DiegoAndai, @mj12albert

@michaldudak michaldudak added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 11, 2023
@DiegoAndai
Copy link
Member

@michaldudak your idea on how to implement this would have to be added to the useAutocomplete hook?

I will add the waiting for upvotes label.

@DiegoAndai DiegoAndai added the waiting for 👍 Waiting for upvotes label Aug 11, 2023
@michaldudak
Copy link
Member

Yes, it could live there, but it requires some bigger refactoring of the hook (which we plan to do anyway)

@DiegoAndai
Copy link
Member

Cool, let's keep it in mind for whenever we get to the refactor.

@Jaswanth-Sriram-Veturi
Copy link
Contributor

+1, I just encountered this and came here searching for the issue

@doougui
Copy link

doougui commented Feb 27, 2024

+1, also encountered the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

6 participants