-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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 - Changing Input programatically #20553
Comments
👋 Thanks for using Material-UI! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://material-ui.com/getting-started/support/. Thanks! If you have a question on StackOverflow, you are welcome to link to it here, it might help others. |
Prefer the React API over firing DOM events unless you are ready to dive into turbulent territories. |
Tip: #18269 (comment). |
You mean By setting the “value” property to a property in React and changing it that way? Will it fire the onChange method? |
The onChange callback will fire if called properly. |
I apologize but I want to get this clear. I am setting the value of the TextField (not autocomplete) via controlled inputs: I'm not sure if I'm missing something here |
Do you have a reproduction? |
Hi, yes, I created a sandbox recreating what I'm trying to do: I forked the code from the Material-UI site (Autocomplete component) and modified it to show you what I'm trying to do. |
Hi, Just an update to this. I keep trying to achieve this by trying to following the "Controlled component" idea using React API (Hooks for the Value and InputValue) and none of them worked as I expected. What worked for me was the following:
Thanks for your guidance! |
@ottogutierrez Doesn't |
@erfansamieyan, I get what you're saying but the issue is that onChange on the Textfield does not get triggered. You can see this example in this Codesandbox. This is how I finally solved my issue |
Current Behavior 😯
I am changing the input of the Autocomplete programatically in the following way:
Expected Behavior 🤔
After selecting the option rendered on the Autocomplete, the onInputChange method has to trigger so the selected option can be saved to state
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: