Pass event instead of value for `onChange`
See original GitHub issueIt would be a lot more useful to pass an event object instead of simply the values when using the onChange prop. By just returning the value(s), there is no way to truly know what Typeahead called it originally, which makes implementing multiple Typaheads in a single form much more difficult (or at least convoluted). To make this functional now, I have to do the following:
The JSX from an overall larger form
<ControlLabel>List1</ControlLabel>
<Typeahead clearButton
multiple
type='text'
name='item1'
value={this.state.item1}
onChange={this.handleItem1Change}
options={this.state.list1}
/>
<ControlLabel>List2</ControlLabel>
<Typeahead clearButton
multiple
type='text'
name='item2'
value={this.state.item2}
onChange={this.handleItem2Change}
options={this.state.list2}
/>
These are the handlers I have to write.
handleItem1Change(value) {
this.handleTypeAheadChange('item1', value);
}
handleItem2Change(value) {
this.handleTypeAheadChange('item2', value);
}
handleTypeAheadChange(name, values) {
this.setState({
[name]: values
});
}
This begs for a single handleChange function much like the example shown in React’s Controlled Component Form. Having to do this workaround doesn’t make any sense, but the way Typeahead’s work right now there doesn’t seem to be any other way that I could find. If there is a much simpler solution I would love to hear about it.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top GitHub Comments
Here’s a simpler way:
As of v3.0.0,
onInputChange
passes the input’s change event as the second param: