This repository was archived by the owner on Dec 30, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
packages/react-instantsearch-dom/src/components Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff 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 } }
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments