Skip to content

Commit

Permalink
improve autoComplete behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
mmintel committed Dec 21, 2017
1 parent 81d5d46 commit fc35f69
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Select extends React.Component {
if (this.props.autoFocus || this.props.autofocus) {
this.focus();
}
if (this.props.autoComplete && this.props.multi) {
console.warn('Warning: To enable autoComplete the prop "multi" must be set to "false".');
}
if (this.isAutoCompleteEnabled()) {
this.addAutoFillListener();
}
Expand Down Expand Up @@ -403,12 +406,9 @@ class Select extends React.Component {
}

handleHiddenInputChange (e) {
const hasValue = this.getValueArray(this.props.value).length;
if (!hasValue) {
this.selectValue({ value: e.target.value });
// basically a change event on the hidden field means the autoComplete function of the browser was used
this.setAutofilled();
}
this.selectValue({ value: e.target.value });
// basically a change event on the hidden field means the autoComplete function of the browser was used
this.setAutofilled();
}


Expand Down Expand Up @@ -835,9 +835,7 @@ class Select extends React.Component {
onClick={onClick}
value={valueArray[0]}
>
{ !this.state.inputValue &&
renderLabel(valueArray[0])
}
{ renderLabel(valueArray[0]) }
</ValueComponent>
);
}
Expand Down Expand Up @@ -1035,7 +1033,7 @@ class Select extends React.Component {

renderHiddenField (valueArray) {
const hasValue = this.getValueArray(this.props.value).length;
const useAutoComplete = this.isAutoCompleteEnabled() && !hasValue;
const useAutoComplete = this.isAutoCompleteEnabled();

if (!this.props.name) return;
if (!this.props.multi || this.props.joinValues) {
Expand Down

0 comments on commit fc35f69

Please sign in to comment.