Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dropdown): fix arrow keys after no results #1279

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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