Skip to content

Commit

Permalink
web: Fix #394 issue with cursor jumping in search components
Browse files Browse the repository at this point in the history
Since the previous setState was called with older currentValue,
the re-render in between onInputChange and setValue used to
reset the input value and then set it back to the latest value
which caused the cursor to jump to the end.

Co-authored-by: Deepak Grover <[email protected]>
  • Loading branch information
divyanshu013 and metagrover committed Aug 24, 2018
1 parent 61e0801 commit 3741c3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
12 changes: 2 additions & 10 deletions packages/web/src/components/search/CategorySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class CategorySearch extends Component {
const performUpdate = () => {
this.setState({
currentValue: value,
suggestions: [],
}, () => {
if (isDefaultValue) {
if (this.props.autosuggest) {
Expand Down Expand Up @@ -409,16 +410,7 @@ class CategorySearch extends Component {
isOpen: true,
});
}
if (value.trim() !== this.state.currentValue.trim()) {
this.setState({
currentValue: value,
suggestions: [],
}, () => {
this.setValue(value);
});
} else {
this.setValue(value);
}
this.setValue(value);
};

onSuggestionSelected = (suggestion) => {
Expand Down
12 changes: 2 additions & 10 deletions packages/web/src/components/search/DataSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class DataSearch extends Component {
const performUpdate = () => {
this.setState({
currentValue: value,
suggestions: [],
}, () => {
if (isDefaultValue) {
if (this.props.autosuggest) {
Expand Down Expand Up @@ -369,16 +370,7 @@ class DataSearch extends Component {
isOpen: true,
});
}
if (value.trim() !== this.state.currentValue.trim()) {
this.setState({
currentValue: value,
suggestions: [],
}, () => {
this.setValue(value);
});
} else {
this.setValue(value);
}
this.setValue(value);
};

onSuggestionSelected = (suggestion) => {
Expand Down

0 comments on commit 3741c3d

Please sign in to comment.