Skip to content

Commit

Permalink
♻️ Instead of blocking enter delays execution
Browse files Browse the repository at this point in the history
  • Loading branch information
massao committed Feb 7, 2019
1 parent caaf129 commit 411bbfb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/components/autoSuggest/index.js
Expand Up @@ -28,6 +28,13 @@ class AutoSuggest extends React.Component {
};
}

componentDidUpdate() {
if (this.shouldSubmit && this.state.placeholder) {
this.handleSubmit();
this.shouldSubmit = false;
}
}

componentWillReceiveProps(nextProps) {
this.selectedRow = null;
const resultsLength = Object.keys(searchEntities).reduce((total, resultKey) =>
Expand Down Expand Up @@ -166,12 +173,15 @@ class AutoSuggest extends React.Component {
}
// If no results found block enter button
/* istanbul ignore else */
if (!(this.state.value.length > 2 && this.state.resultsLength === 0)) {
if (this.state.resultsLength > 0 || this.state.placeholder !== '') {
this.submitSearch();
} else {
this.submitAnySearch();
}
if (this.state.value.length > 2 && this.state.resultsLength === 0) {
this.shouldSubmit = true;
return;
}

if (this.state.resultsLength > 0 || this.state.placeholder !== '') {
this.submitSearch();
} else {
this.submitAnySearch();
}
}

Expand All @@ -194,6 +204,7 @@ class AutoSuggest extends React.Component {
break;
/* istanbul ignore next */
default:
this.shouldSubmit = false;
break;
}
return false;
Expand Down

0 comments on commit 411bbfb

Please sign in to comment.