Skip to content

Commit

Permalink
fixed regressions in the following PRs: 2215, 2205 and 2226
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyneplaine committed Jan 4, 2018
1 parent d2a3afd commit 6415163
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,19 @@ class Select extends React.Component {
this.setState({ required: false });
}

if (this.state.inputValue && this.props.value !== nextProps.value && nextProps.onSelectResetsInput) {
this.setState({ inputValue: this.handleInputValueChange('') });
// Here we only want to clear the input value under the following conditions.
// 1. There currently actually is an inputValue in state
// 2. The new value is different to the old value OR the new value is == null
// 3. The new value is not the same as the last set value OR onSelectResetsInput has been enabled
if (this.state.inputValue
&& (this.props.value !== nextProps.value || !nextProps.value)
&& (nextProps.value !== this._lastSetValue || nextProps.onSelectResetsInput)) {
this.setState({
inputValue: this.handleInputValueChange('')
});
}

delete this._lastSetValue;
}

componentDidUpdate (prevProps, prevState) {
Expand Down Expand Up @@ -589,10 +599,11 @@ class Select extends React.Component {
const required = this.handleRequired(value, this.props.multi);
this.setState({ required });
}
if (this.props.simpleValue && value) {
value = this.props.multi ? value.map(i => i[this.props.valueKey]).join(this.props.delimiter) : value[this.props.valueKey];
}
this._lastSetValue = value;
if (this.props.onChange) {
if (this.props.simpleValue && value) {
value = this.props.multi ? value.map(i => i[this.props.valueKey]).join(this.props.delimiter) : value[this.props.valueKey];
}
this.props.onChange(value);
}
}
Expand Down Expand Up @@ -719,11 +730,14 @@ class Select extends React.Component {
.filter(option => !option.option.disabled);
this._scrollToFocusedOptionOnUpdate = true;
if (!this.state.isOpen) {
this.setState({
const newState = {
isOpen: true,
inputValue: '',
focusedOption: this._focusedOption || (options.length ? options[dir === 'next' ? 0 : options.length - 1].option : null)
});
};
if (!this.props.onSelectResetsInput) {
newState.inputValue = '';
}
this.setState(newState);
return;
}
if (!options.length) return;
Expand Down

0 comments on commit 6415163

Please sign in to comment.