Skip to content

Commit 0ea4950

Browse files
francoischalifourHaroenv
authored andcommitted
fix(searchBox): update lifecycle state (#3981)
1 parent 2b08344 commit 0ea4950

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/connectors/search-box/__tests__/connectSearchBox-test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,33 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/search-box/
294294
const makeWidget = connectSearchBox(renderFn);
295295
const widget = makeWidget();
296296

297-
const nextConfiguration = widget.getConfiguration();
297+
const nextConfiguration = widget.getConfiguration(
298+
new SearchParameters({})
299+
);
300+
301+
expect(nextConfiguration).toEqual(
302+
new SearchParameters({
303+
query: '',
304+
})
305+
);
306+
});
307+
308+
it('takes the default `query` from the `SearchParameters` passed', () => {
309+
const renderFn = () => {};
310+
const makeWidget = connectSearchBox(renderFn);
311+
const widget = makeWidget();
298312

299-
expect(nextConfiguration.query).toBe('');
313+
const nextConfiguration = widget.getConfiguration(
314+
new SearchParameters({
315+
query: 'Previous query',
316+
})
317+
);
318+
319+
expect(nextConfiguration).toEqual(
320+
new SearchParameters({
321+
query: 'Previous query',
322+
})
323+
);
300324
});
301325
});
302326

src/connectors/search-box/connectSearchBox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ export default function connectSearchBox(renderFn, unmountFn = noop) {
8686
this._clear();
8787
},
8888

89-
getConfiguration() {
90-
return {
91-
query: '',
92-
};
89+
getConfiguration(state) {
90+
return state.setQueryParameters({
91+
query: state.query || '',
92+
});
9393
},
9494

9595
init({ helper, instantSearchInstance }) {

0 commit comments

Comments
 (0)