diff --git a/src/__tests__/downshift.get-item-props.js b/src/__tests__/downshift.get-item-props.js index 5b1099dcb..336ab3383 100644 --- a/src/__tests__/downshift.get-item-props.js +++ b/src/__tests__/downshift.get-item-props.js @@ -50,6 +50,19 @@ test('on mouseenter of an item updates the highlightedIndex to that item', () => ) }) +test('after selecting an item highlightedIndex should be reset to defaultHighlightIndex', () => { + const {Component, childSpy} = setup() + const wrapper = mount() + const firstButton = wrapper.find('button').first() + childSpy.mockClear() + firstButton.simulate('click') + expect(childSpy).toHaveBeenCalledWith( + expect.objectContaining({ + highlightedIndex: 1, + }), + ) +}) + test('getItemProps throws a helpful error when no object is given', () => { expect(() => mount( diff --git a/src/downshift.js b/src/downshift.js index d45af9eac..2ee341460 100644 --- a/src/downshift.js +++ b/src/downshift.js @@ -217,7 +217,7 @@ class Downshift extends Component { this.internalSetState( { isOpen: false, - highlightedIndex: null, + highlightedIndex: this.props.defaultHighlightedIndex, selectedItem: item, inputValue: this.props.itemToString(item), ...otherStateToSet,