Skip to content

Commit

Permalink
fix: reset highlightedIndex to defaultHighlightIndex after selecting …
Browse files Browse the repository at this point in the history
…item (#195)
  • Loading branch information
SpaceK33z authored and Kent C. Dodds committed Sep 21, 2017
1 parent d48031f commit efbbe19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/__tests__/downshift.get-item-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Component defaultHighlightedIndex={1} />)
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(
Expand Down
2 changes: 1 addition & 1 deletion src/downshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit efbbe19

Please sign in to comment.