-
Notifications
You must be signed in to change notification settings - Fork 401
Closed
Labels
Description
Describe the solution you'd like
I'm looking for a way to display some information under the input when a Token has been clicked. A nice way to do it would be as follows:
<Typeahead
id="values-typeahead"
clearButton
defaultSelected={initValues}
multiple
onChange={this.handleValuesSelected}
options={values}
placeholder="Choose values..."
renderToken={(
selectedItem: string,
props: any,
index: number
) => {
return (
<Token
key={index}
onRemove={props.onRemove!}
onClick={() => {
console.log(`${selectedItem} selected`);
}}>
{selectedItem}
</Token>
);
}}
/>How is this solution useful to others?
Triggering an action when clicking on a token could interest others I guess.
Describe alternatives you've considered
Writing a custom renderToken method using the tokenContainer, but combined with TypeScript this rapidly seems too much for just a simple click 'listener'.
Additional context
If the feature is to be implemented with the above code, a simple way to do it would be to add to modify in tokenContainer, the _handleActive from
_handleActive = (e) => {
e.stopPropagation();
this.setState({active: true});
}to
_handleActive = (e) => {
e.stopPropagation();
this.setState({active: true});
if (this.props.onClick) {
this.props.onClick();
}
}In fact, it's what I'm using now :)
I'd be glad to open a PR if you want!