After selecting item on Typeahead, onChange callback triggered twice.
See original GitHub issueVersion
2.4.0
Steps to reproduce
Add Typeahead
component which looks like this
<Typeahead
onChange={(selected) => {
this.setState({selected});
}}
options={['one', 'two']}
selected={this.state.selected}
/>
Breakpoint inside on onChange
Select any item
Expected Behavior
onChange
callback hitted once
Actual Behavior
onChange
callback hitted twice
Notes
It looks like first call is comming from typeaheadInputContainer.js
. Whenever user selects item, _handleChange
for Input
got executed, which triggers this.props.onChange(...)
.
Second call is comming from typeaheadContainer.js
because selected
prop is updated, which triggers componentWillReceiveProps(...)
-> this._updateText(...)
-> this.props.onInputChange(...)
-> this.props.onChange()
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:20 (9 by maintainers)
Top Results From Across the Web
Why Type Ahead Text Control logs onChange Event twice if ...
I'm using Type Ahead Text Control from IBM BPM UI toolkit ; I notice it logs onChange Event twice if an item is...
Read more >react-bootstrap-typeahead How do I trigger a callback (update ...
When finished selecting, he can press Enter to push his selections into an array in the state. The input will then clear and...
Read more >jQuery | Autocomplete Selection Event - GeeksforGeeks
The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.
Read more >Fire OnChange only once - Telerik UI for Blazor
I observe twice firing onchange event in dropdownlist or other inputs. I want the event to fire only once when the user selects...
Read more >How to Use Browser Event Listeners in React for Search and ...
js app that I put together just to get up and running with an example of search with autocomplete using The Star Wars...
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
I’m agree with @coolkev on his last comment in #305
Thanks for the report. Sounds like the behavior described in #305. It’s the expected behavior as written, but is unexpected compared to how typical form elements work. Seems like I need to rethink a bit how and where
onChange
andonInputChange
are being called.