Skip to content

Commit

Permalink
fix(withSearchBox): keep displaying searchBox when no items found (#1930
Browse files Browse the repository at this point in the history
)

Before this commit, the SearchBox inside RefinementList was being
unmounted as soon as the search for items was not retrieving anything.
  • Loading branch information
vvo authored and mthuret committed Feb 1, 2017
1 parent c4ed992 commit 30de4cd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/react-instantsearch/src/components/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class List extends Component {

this.state = {
extended: false,
query: '',
};
}

Expand Down Expand Up @@ -95,7 +96,8 @@ class List extends Component {

renderSearchBox() {
const {cx, searchForItems, isFromSearch, translate, items, selectItem} = this.props;
const noResults = items.length === 0 ? <div {...cx('noResults')}>{translate('noResults')}</div> : null;
const noResults = items.length === 0 &&
this.state.query !== '' ? <div {...cx('noResults')}>{translate('noResults')}</div> : null;
return <div {...cx('SearchBox')}>
<SearchBox
currentRefinement={isFromSearch ? this.state.query : ''}
Expand All @@ -119,7 +121,7 @@ class List extends Component {

render() {
const {cx, items, withSearchBox, canRefine} = this.props;
const searchBox = withSearchBox && canRefine ? this.renderSearchBox() : null;
const searchBox = withSearchBox ? this.renderSearchBox() : null;
if (items.length === 0) {
return <div {...cx('root', !canRefine && 'noRefinement')}>
{searchBox}
Expand Down

0 comments on commit 30de4cd

Please sign in to comment.