Skip to content

Commit

Permalink
fix(Dropdown): fix arrow keys after no results (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason authored Feb 3, 2017
1 parent 0372af2 commit ced73f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export default class Dropdown extends Component {
if (search && newQuery && !open) this.open()

this.setState({
selectedIndex: this.getEnabledIndices()[0],
selectedIndex: 0,
searchQuery: newQuery,
})
}
Expand Down
38 changes: 38 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,44 @@ describe('Dropdown Component', () => {
.find('.selected')
.should.contain.text('a2')
})
it('still works after encountering "no results"', () => {
const opts = [
{ text: 'a1', value: 'a1' },
{ text: 'a2', value: 'a2' },
{ text: 'a3', value: 'a3' },
]
wrapperMount(<Dropdown options={opts} search selection />)

// search for 'a4'
// no results appears
wrapper
.simulate('click')
.find('input.search')
.simulate('change', { target: { value: 'a4' } })

wrapper.should.have.exactly(1).descendants('.message')

// search for 'a' (simulated backspace)
// no results is removed
// first item is selected
// down arrow moves selection
wrapper
.find('input.search')
.simulate('change', { target: { value: 'a' } })

wrapper.should.not.have.descendants('.message')

wrapper
.should.have.exactly(1).descendants('.selected')
.which.contain.text('a1')

// move selection down
domEvent.keyDown(document, { key: 'ArrowDown' })

wrapper
.should.have.exactly(1).descendants('.selected')
.which.contain.text('a2')
})
it('skips over disabled items', () => {
const opts = [
{ text: 'a1', value: 'a1' },
Expand Down

0 comments on commit ced73f2

Please sign in to comment.