Skip to content

Commit c073a9a

Browse files
fix(searchBox): add reusable SearchBox component (#3489)
1 parent a2a800b commit c073a9a

File tree

16 files changed

+1291
-1078
lines changed

16 files changed

+1291
-1078
lines changed

src/components/RefinementList/RefinementList.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import isEqual from 'lodash/isEqual';
55
import { isSpecialClick } from '../../lib/utils';
66
import Template from '../Template/Template';
77
import RefinementListItem from './RefinementListItem';
8-
import SearchBox from '../SearchBox/Searchbox';
8+
import SearchBox from '../SearchBox/SearchBox';
99

1010
class RefinementList extends Component {
1111
constructor(props) {
@@ -129,8 +129,8 @@ class RefinementList extends Component {
129129
}
130130

131131
componentWillReceiveProps(nextProps) {
132-
if (this.searchbox && !nextProps.isFromSearch) {
133-
this.searchbox.clearInput();
132+
if (this.searchBox && !nextProps.isFromSearch) {
133+
this.searchBox.resetInput();
134134
}
135135
}
136136

@@ -177,13 +177,17 @@ class RefinementList extends Component {
177177
const searchBox = this.props.searchFacetValues && (
178178
<div className={this.props.cssClasses.searchBox}>
179179
<SearchBox
180-
ref={i => {
181-
this.searchbox = i;
182-
}}
180+
ref={searchBoxRef => (this.searchBox = searchBoxRef)}
183181
placeholder={this.props.searchPlaceholder}
184-
onChange={this.props.searchFacetValues}
185-
onValidate={() => this.refineFirstValue()}
186182
disabled={shouldDisableSearchBox}
183+
cssClasses={this.props.cssClasses.searchable}
184+
templates={this.props.templateProps.templates}
185+
onChange={event => this.props.searchFacetValues(event.target.value)}
186+
onReset={() => this.props.searchFacetValues('')}
187+
onSubmit={() => this.refineFirstValue()}
188+
// This sets the search box to a controlled state because
189+
// we don't rely on the `refine` prop but on `onChange`.
190+
searchAsYouType={false}
187191
/>
188192
</div>
189193
);
@@ -247,6 +251,17 @@ RefinementList.propTypes = {
247251
showMore: PropTypes.string,
248252
disabledShowMore: PropTypes.string,
249253
disabledItem: PropTypes.string,
254+
searchable: PropTypes.shape({
255+
root: PropTypes.string,
256+
form: PropTypes.string,
257+
input: PropTypes.string,
258+
submit: PropTypes.string,
259+
submitIcon: PropTypes.string,
260+
reset: PropTypes.string,
261+
resetIcon: PropTypes.string,
262+
loadingIndicator: PropTypes.string,
263+
loadingIcon: PropTypes.string,
264+
}),
250265
}).isRequired,
251266
depth: PropTypes.number,
252267
facetValues: PropTypes.array,

src/components/RefinementList/__tests__/RefinementList-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('RefinementList', () => {
2828
...defaultProps,
2929
cssClasses: {
3030
root: 'root',
31+
searchable: {},
3132
},
3233
};
3334

@@ -41,6 +42,7 @@ describe('RefinementList', () => {
4142
...defaultProps,
4243
cssClasses: {
4344
item: 'item',
45+
searchable: {},
4446
},
4547
facetValues: [{ value: 'foo', isRefined: true }],
4648
};
@@ -55,6 +57,7 @@ describe('RefinementList', () => {
5557
...defaultProps,
5658
cssClasses: {
5759
selectedItem: 'active',
60+
searchable: {},
5861
},
5962
facetValues: [
6063
{ value: 'foo', isRefined: true },
@@ -232,6 +235,17 @@ describe('RefinementList', () => {
232235
noResults: 'noResults',
233236
showMore: 'showMore',
234237
disabledShowMore: 'disabledShowMore',
238+
searchable: {
239+
root: 'root',
240+
form: 'form',
241+
input: 'input',
242+
submit: 'submit',
243+
submitIcon: 'submitIcon',
244+
reset: 'reset',
245+
resetIcon: 'resetIcon',
246+
loadingIndicator: 'loadingIndicator',
247+
loadingIcon: 'loadingIcon',
248+
},
235249
};
236250

237251
it('without facets', () => {
@@ -263,6 +277,9 @@ describe('RefinementList', () => {
263277
templates: {
264278
item: item => item,
265279
searchableNoResults: x => x,
280+
reset: 'reset',
281+
submit: 'submit',
282+
loadingIndicator: 'loadingIndicator',
266283
},
267284
},
268285
toggleRefinement: () => {},
@@ -397,6 +414,9 @@ describe('RefinementList', () => {
397414
templateProps: {
398415
templates: {
399416
item: item => item,
417+
reset: 'reset',
418+
submit: 'submit',
419+
loadingIndicator: 'loadingIndicator',
400420
},
401421
},
402422
toggleRefinement: () => {},

0 commit comments

Comments
 (0)