Possibility to have only unique values in TagInput component.
Concerns:
TagInput component?@JacekJagiello I do not think this feature belongs in TagInput--it goes against the fully controlled nature of the API. Also, the code is simple enough (in your PR) that there's little value in including it directly in the component: it's just a single filter, and I'm sure that defining uniqueness based only on strict string equality will not be sufficient across the board.
Something that I thought about while developing this initial version was supporting a return value from onAdd to control the input-clearing behavior: return false to say "I don't want to add this," and the component will ignore the event and not clear the input. That alone would allow users to implement whatever sort of behavior they like. (Same thing for onRemove is less valuable cuz there's no behavior in the component--removing the item is user code responsibility.)
How does that sound, instead of this feature?
@giladgray Yeah, valid points. Supporting a return value definitely sound better. ;) Can you elaborate this feature more? I mean, for me it means something as simple as:
const onAddResult = Utils.safeInvoke(this.props.onAdd, value);
if (onAddResult !== false) {
this.setState({ inputValue: "" });
}
When onAdd can return boolean | void. Is that all or I miss something?
Ps. Sorry for wrong issue number in commits. I referred this issue instead of 1220, but I've fixed commit names.
@JacekJagiello I agree with Gilad, let's keep the component fully controlled. Your little snippet for onAdd?: (value: string) => boolean | void seems good, would you like to try and open a PR for it? You could then add a "Unique values only" toggle to the example to showcase this upgraded onAdd callback 馃挴
@llorca Sure, can you close this issue and start a new one? Or do you want to keep this under current issue?
@JacekJagiello We can keep this issue open and close up the current PR 馃憤
@llorca @giladgray @JacekJagiello - I took a stab at this in #1309. Lemme know how that looks.
Most helpful comment
@JacekJagiello I do not think this feature belongs in
TagInput--it goes against the fully controlled nature of the API. Also, the code is simple enough (in your PR) that there's little value in including it directly in the component: it's just a singlefilter, and I'm sure that defining uniqueness based only on strict string equality will not be sufficient across the board.Something that I thought about while developing this initial version was supporting a return value from
onAddto control the input-clearing behavior: returnfalseto say "I don't want to add this," and the component will ignore the event and not clear the input. That alone would allow users to implement whatever sort of behavior they like. (Same thing foronRemoveis less valuable cuz there's no behavior in the component--removing the item is user code responsibility.)How does that sound, instead of this feature?