Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 04f3644

Browse files
authored
fix(RefinementList): prevent searchable component to refine on empty list (#3059)
1 parent 408739b commit 04f3644

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/react-instantsearch-dom/src/components/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class List extends Component {
131131
onSubmit={e => {
132132
e.preventDefault();
133133
e.stopPropagation();
134-
if (isFromSearch) {
134+
if (isFromSearch && items.length > 0) {
135135
selectItem(items[0], this.resetQuery);
136136
}
137137
}}

packages/react-instantsearch-dom/src/components/__tests__/RefinementList.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,34 @@ describe('RefinementList', () => {
330330

331331
wrapper.unmount();
332332
});
333+
334+
it('hit enter on an empty search values results list should do nothing', () => {
335+
const emptyRefinementList = (
336+
<RefinementList
337+
refine={refine}
338+
searchable
339+
searchForItems={searchForItems}
340+
createURL={() => '#'}
341+
items={[]}
342+
isFromSearch={true}
343+
canRefine={true}
344+
/>
345+
);
346+
347+
refine.mockClear();
348+
const wrapper = mount(emptyRefinementList);
349+
const input = wrapper.find('input[type="search"]');
350+
input.props().value = 'white';
351+
352+
wrapper.find('form').simulate('submit');
353+
354+
expect(refine.mock.calls).toHaveLength(0);
355+
expect(input.props().value).toBe('white');
356+
357+
const selectedRefinements = wrapper.find('li');
358+
expect(selectedRefinements).toHaveLength(0);
359+
360+
wrapper.unmount();
361+
});
333362
});
334363
});

0 commit comments

Comments
 (0)