-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Prevent onInputChange when onChange is fired #18784
Comments
@Tybot204 We have a related issue in #18656 where we plan to switch the call order between In the google map demo, we hack this problem a bit as we listen for the change event on the text field. Changing the change event behavior is not an option, the autocomplete value and autocomplete input value are two independent states. The alternative I can think of is to provide a dedicated prop for the data fetching prop. For instance, react-autosuggest has a I think that we can add a third argument to the |
@oliviertassinari Ah switching the order makes sense to me. I did notice they fired in reverse order than I initially expected. You're right though, it wouldn't completely solve this issue since I think adding a |
Turns out I had some extra time this afternoon to add the |
@Tybot204 Loving it, thank you |
@oliviertassinari
What if I don't want to do that? |
@eawtf Control the inputValue state, ignore the reset event. |
One of the possible solution to prevent executing
Here, |
I have the same problem. My solution is to check the event "type" onInputChange = {(e,v) =>{
if(e.type=== "change") //e.type = "click" when option is selected
setQueryPatient(RegExp.escape(v.toLocaleLowerCase()));
}}` |
I'm not really sure whether to classify this as a bug or feature request as I'm not familiar with what's actually intended here.
When
onChange
is fired,onInputChange
is also fired, even though the user is not actually typing into the search box. Technically, the text input is changing though, so it makes sense from that standpoint that this would happen.Summary 💡
I would argue the
onInputChange
event should not fire when a user selects an option, and instead only fires when they type into the input field themselves.Motivation 🔦
This is preventing me from tying an external API request to the user typing in the text field for search, as once the user selects an option, an extra API request is made with the full selection label. I don't want to make an extra request on user selection, as the options available to the user should remain the same.
I have also tried storing the selected option in state and checking that the selected option and the input don't match before making my API request. However, both
onChange
andonInputChange
are executed before the state actually updates in React, so my check is always one state behind.The text was updated successfully, but these errors were encountered: