Skip to content

Commit

Permalink
fix(searchbox): handle default search query for demos
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjithkumar017 committed May 22, 2021
1 parent 31e379a commit a537950
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/modules/searchBox/SearchBoxContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class SearchBoxContainer extends React.PureComponent {
}

componentDidUpdate(prevProps) {
const { unbxdCore, unbxdCoreStatus, query, productType } = this.props;
const {
unbxdCore,
unbxdCoreStatus,
query,
productType,
defaultSearch
} = this.props;
const { q: currentQuery } = unbxdCore.getQueryParams();
if (
unbxdCoreStatus !== prevProps.unbxdCoreStatus &&
Expand All @@ -105,6 +111,20 @@ class SearchBoxContainer extends React.PureComponent {
) {
this.setState({ query: currentQuery });
}

if (
defaultSearch !== currentQuery &&
typeof defaultSearch === 'string' &&
unbxdCoreStatus !== searchStatus.LOADING &&
defaultSearch.length > 0 &&
currentQuery === undefined
) {
const {
helpers: { setSearchBoxConfiguration }
} = this.props;
this.setState({ query: defaultSearch });
setSearchBoxConfiguration({ query: defaultSearch });
}
}

getSearchBoxProps() {
Expand Down

0 comments on commit a537950

Please sign in to comment.