Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't clear TagInput inputValue state if controlled #3137

Merged
merged 3 commits into from
Nov 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/core/src/components/tag-input/tagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ export class TagInput extends AbstractPureComponent<ITagInputProps, ITagInputSta
addOnBlur: false,
addOnPaste: true,
inputProps: {},
inputValue: "",
separator: /[,\n\r]/,
tagProps: {},
};

public state: ITagInputState = {
activeIndex: NONE,
inputValue: this.props.inputValue || "",
inputValue: this.props.inputValue,
isInputFocused: false,
};

Expand All @@ -206,7 +207,7 @@ export class TagInput extends AbstractPureComponent<ITagInputProps, ITagInputSta
super.componentWillReceiveProps(nextProps);

if (nextProps.inputValue !== this.props.inputValue) {
this.setState({ inputValue: nextProps.inputValue || "" });
this.setState({ inputValue: nextProps.inputValue });
}
}

Expand Down Expand Up @@ -262,8 +263,8 @@ export class TagInput extends AbstractPureComponent<ITagInputProps, ITagInputSta
private addTags = (value: string) => {
const { inputValue, onAdd, onChange, values } = this.props;
const newValues = this.getValues(value);
let shouldClearInput = inputValue === undefined;
shouldClearInput = Utils.safeInvoke(onAdd, newValues) !== false && shouldClearInput;
let shouldClearInput =
Utils.safeInvoke(onAdd, newValues) !== false && inputValue === TagInput.defaultProps.inputValue;
giladgray marked this conversation as resolved.
Show resolved Hide resolved
// avoid a potentially expensive computation if this prop is omitted
if (Utils.isFunction(onChange)) {
shouldClearInput = onChange([...values, ...newValues]) !== false && shouldClearInput;
Expand Down