onChange is triggered when typing in AsyncTypeahead single input
See original GitHub issueHopefully this bug report makes sense! It might also just be me misunderstanding the API, but I managed to set up the multiple input version of the component just fine and so I’m not sure what’s going wrong when I try to use the single input version…
Version
5.0.0-alpha.1
Steps to reproduce
Use an AsyncTypeahead single input component:
<AsyncTypeahead
multiple={false}
onChange={selected => {
console.log('// onChange')
}}
onInputChange={text => {
console.log('// onInputChange')
}}
options={autocompleteOptions}
onSearch={queryString => {
console.log('// onSearch')
}}
selected={selectedItem}
/>
Expected Behavior
When I type in the input, I would expect onInputChange
and onSearch
to trigger, but not onChange
(which I would expect to only trigger once a selection is actually made).
Actual Behavior
onChange
is triggered immediately when typing, which updates selectedItem
and prevents the controlled component from actually changing.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
onChange handler in async typeahead is not called when ...
They are triggered when I type something on UI and select one option from typeahead dropdown. But from tests, both onChange and selected...
Read more >React Bootstrap Typeahead Example
The typeahead allows single-selection by default. Setting the multiple prop turns the component into a tokenizer, allowing multiple selections. Example.
Read more >How to Use the Enter Key Event Handler on a React-Bootstrap ...
These events are triggered when users touch, release, or hold keys, and they are used to to process specific user input.
Read more >How To Create Searchable, Async Dropdowns with React ...
If you interact with this menu, you will trigger an onChange event and log messages to the console. By opening your browser's developer ......
Read more >Examples - Final Form Docs
Uses the built-in React inputs: input , select , and textarea to build a form ... it's so easy to write one recursively...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right, I was just hardcoding it as a quick example. But your reply helped me figure out the issue! In my actual code the flow looks like this:
selected
from its parentselected
in the parent’s stateBasically I was missing a step to update the parent component’s state to clear the value. I’ve added this to the
onChange
and it seems to work:Thanks for helping me work this out! Great component btw, I’m planning to include it as one of the default Vulcan.js components 😃
Awesome! Glad you were able to solve the issue 😃