Skip to content

Commit 3d95d4c

Browse files
authored
fix(sffv): when using a large limit, retain the search (#2163)
In the case we're using the widget with a very big limit (number of items displayed) in the refinement list, we often still have a huge number of items. Therefore we should be able to continue searching in the list, even though all the items are displayed. Fixes #2156
1 parent 4a13810 commit 3d95d4c

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

dev/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,31 @@ search.addWidget(
207207
})
208208
);
209209

210+
search.addWidget(
211+
instantsearch.widgets.refinementList({
212+
container: '#searchable-brands-alwaysActive',
213+
attributeName: 'brand',
214+
operator: 'or',
215+
limit: 10,
216+
cssClasses: {
217+
header: 'facet-title',
218+
item: 'facet-value checkbox',
219+
count: 'facet-count pull-right',
220+
active: 'facet-active',
221+
},
222+
templates: {
223+
header: 'Searchable brands',
224+
},
225+
searchForFacetValues: {
226+
placeholder: 'Find other brands...',
227+
templates: {
228+
noResults: 'No results',
229+
},
230+
isAlwaysActive: true,
231+
},
232+
})
233+
);
234+
210235
search.addWidget(
211236
instantsearch.widgets.refinementList({
212237
collapsible: {

dev/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ <h1><a href="./">Instant search demo</a> <small>using instantsearch.js</small></
2323
<div class="facet" id="current-refined-values"></div>
2424
<div class="facet" id="hierarchical-categories"></div>
2525
<div class="facet" id="searchable-brands"></div>
26+
<div class="facet" id="searchable-brands-alwaysActive"></div>
2627
<div class="facet" id="brands"></div>
2728
<div class="facet" id="brands-2"></div>
2829
<div class="facet" id="price-range"></div>

src/components/RefinementList/RefinementList.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ class RefinementList extends React.Component {
160160
/> :
161161
undefined;
162162

163+
const shouldDisableSearchInput =
164+
this.props.searchIsAlwaysActive !== true &&
165+
!(this.props.isFromSearch || displayedFacetValues.length >= limit);
163166
const searchInput = this.props.searchFacetValues ?
164-
<SearchBox ref={i => { this.searchbox = i; }}
165-
placeholder={this.props.searchPlaceholder}
166-
onChange={this.props.searchFacetValues}
167-
onValidate={() => this.refineFirstValue()}
168-
disabled={!this.props.isFromSearch && displayedFacetValues.length < limit}/> :
169-
null;
167+
<SearchBox ref={i => { this.searchbox = i; }}
168+
placeholder={this.props.searchPlaceholder}
169+
onChange={this.props.searchFacetValues}
170+
onValidate={() => this.refineFirstValue()}
171+
disabled={shouldDisableSearchInput}/> : null;
170172

171173
const noResults = this.props.searchFacetValues && this.props.isFromSearch && this.props.facetValues.length === 0 ?
172174
<Template
@@ -205,6 +207,7 @@ RefinementList.propTypes = {
205207
toggleRefinement: React.PropTypes.func.isRequired,
206208
searchFacetValues: React.PropTypes.func,
207209
searchPlaceholder: React.PropTypes.string,
210+
searchIsAlwaysActive: React.PropTypes.bool,
208211
isFromSearch: React.PropTypes.bool,
209212
};
210213

src/widgets/refinement-list/refinement-list.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const bem = bemHelper('ais-refinement-list');
2626
* @param {string} [options.limit=10] How much facet values to get. When the show more feature is activated this is the minimum number of facets requested (the show more button is not in active state). [*]
2727
* @param {object|boolean} [options.searchForFacetValues=false] Add a search input to let the user search for more facet values
2828
* @param {string} [options.searchForFacetValues.placeholder] Value of the search field placeholder
29+
* @param {boolean} [options.searchForFacetValues.isAlwaysActive=false] When `false` the search field will become disabled if
30+
* there are less items to display than the `options.limit`, otherwise the search field is always usable.
2931
* @param {string} [options.searchForFacetValues.templates] Templates to use for search for facet values
3032
* @param {string} [options.searchForFacetValues.templates.noResults] Templates to use for search for facet values
3133
* @param {object|boolean} [options.showMore=false] Limit the number of results and display a showMore button
@@ -68,7 +70,7 @@ refinementList({
6870
[ collapsible=false ],
6971
[ showMore.{templates: {active, inactive}, limit} ],
7072
[ collapsible=false ],
71-
[ searchForFacetValues.{placeholder, templates: {noResults}}],
73+
[ searchForFacetValues.{placeholder, templates: {noResults}, isAlwaysActive}],
7274
})`;
7375
function refinementList({
7476
container,
@@ -165,6 +167,7 @@ function refinementList({
165167
toggleRefinement={toggleRefinement}
166168
searchFacetValues={searchFacetValues}
167169
searchPlaceholder={searchForFacetValues.placeholder || 'Search for other...'}
170+
searchIsAlwaysActive={searchForFacetValues.isAlwaysActive || false}
168171
isFromSearch={isFromSearch}
169172
/>,
170173
containerNode

0 commit comments

Comments
 (0)