Skip to content

Commit

Permalink
fix(web): controlled behavior with URLparams
Browse files Browse the repository at this point in the history
  • Loading branch information
bietkul committed Jun 21, 2019
1 parent 8299806 commit d5d46f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions packages/web/src/components/search/CategorySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class CategorySearch extends Component {
const cause = null;

if (currentValue) {
if (props.onChange) {
props.onChange(currentValue);
}
this.setValue(currentValue, true, props, currentCategory, cause, hasMounted);
}
}
Expand Down Expand Up @@ -405,9 +408,9 @@ class CategorySearch extends Component {
() => {
if (isDefaultValue) {
if (this.props.autosuggest) {
this.setState({
isOpen: false,
});
// this.setState({
// isOpen: false,
// });
this.updateDefaultQuery(value, props);
}
// in case of strict selection only SUGGESTION_SELECT should be able
Expand Down Expand Up @@ -560,7 +563,9 @@ class CategorySearch extends Component {
term: suggestion.value,
category: suggestion.category || null,
};

this.setState({
isOpen: false,
});
if (value === undefined) {
this.setValue(
currentValue.term,
Expand Down
13 changes: 9 additions & 4 deletions packages/web/src/components/search/DataSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class DataSearch extends Component {
const cause = null;

if (currentValue) {
if (props.onChange) {
props.onChange(currentValue);
}
this.setValue(currentValue, true, props, cause, hasMounted);
}
}
Expand Down Expand Up @@ -141,7 +144,6 @@ class DataSearch extends Component {
this.updateQuery(this.state.currentValue, this.props);
},
);

if (this.props.value !== prevProps.value) {
this.setValue(this.props.value, true, this.props);
} else if (
Expand Down Expand Up @@ -338,9 +340,9 @@ class DataSearch extends Component {
() => {
if (isDefaultValue) {
if (this.props.autosuggest) {
this.setState({
isOpen: false,
});
// this.setState({
// isOpen: false,
// });
this.updateDefaultQuery(value, props);
}
// in case of strict selection only SUGGESTION_SELECT should be able
Expand Down Expand Up @@ -481,6 +483,9 @@ class DataSearch extends Component {

onSuggestionSelected = (suggestion) => {
const { value, onChange } = this.props;
this.setState({
isOpen: false,
});
if (value === undefined) {
this.setValue(suggestion.value, true, this.props, causes.SUGGESTION_SELECT);
} else if (onChange) {
Expand Down

0 comments on commit d5d46f5

Please sign in to comment.