Skip to content

Commit

Permalink
Reset focused suggestion when suggestions are not rendered. Fixes #234.
Browse files Browse the repository at this point in the history
  • Loading branch information
moroshko committed Sep 3, 2016
1 parent 7c9089e commit a759a25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Autosuggest extends Component {
if (isCollapsed && !this.justSelectedSuggestion) {
revealSuggestions();
}
} else {
this.resetFocusedSuggestion();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/async-suggestions/AutosuggestApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export default class AutosuggestApp extends Component {
onSuggestionsClearRequested={onSuggestionsClearRequested}
getSuggestionValue={getSuggestionValue}
renderSuggestion={renderSuggestion}
inputProps={inputProps} />
inputProps={inputProps}
focusFirstSuggestion={true} />
);
}
}
9 changes: 9 additions & 0 deletions test/async-suggestions/AutosuggestApp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ describe('Autosuggest that gets suggestions asynchronously', () => {
tick(500);
expectSuggestions([]);
});

it('should not error if suggestions were cleared after having suggestions', () => {
focusAndSetInputValue('p');
tick(100);
focusAndSetInputValue('pz');
tick(100);
clickEnter();
expectSuggestions([]);
});
});
});

0 comments on commit a759a25

Please sign in to comment.