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

Commit

Permalink
fix(RefinementList): prevent searchable component to refine on empty …
Browse files Browse the repository at this point in the history
…list (#3059)
  • Loading branch information
shortcuts committed Jun 9, 2021
1 parent 408739b commit 04f3644
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-instantsearch-dom/src/components/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class List extends Component {
onSubmit={e => {
e.preventDefault();
e.stopPropagation();
if (isFromSearch) {
if (isFromSearch && items.length > 0) {
selectItem(items[0], this.resetQuery);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,34 @@ describe('RefinementList', () => {

wrapper.unmount();
});

it('hit enter on an empty search values results list should do nothing', () => {
const emptyRefinementList = (
<RefinementList
refine={refine}
searchable
searchForItems={searchForItems}
createURL={() => '#'}
items={[]}
isFromSearch={true}
canRefine={true}
/>
);

refine.mockClear();
const wrapper = mount(emptyRefinementList);
const input = wrapper.find('input[type="search"]');
input.props().value = 'white';

wrapper.find('form').simulate('submit');

expect(refine.mock.calls).toHaveLength(0);
expect(input.props().value).toBe('white');

const selectedRefinements = wrapper.find('li');
expect(selectedRefinements).toHaveLength(0);

wrapper.unmount();
});
});
});

0 comments on commit 04f3644

Please sign in to comment.