From 9ab11998efa8cfb93d7b79f345bf247ba99fc1e4 Mon Sep 17 00:00:00 2001 From: Levi Thomason Date: Fri, 3 Feb 2017 10:01:02 -0800 Subject: [PATCH] fix(Dropdown): fix arrow keys after no results --- src/modules/Dropdown/Dropdown.js | 2 +- test/specs/modules/Dropdown/Dropdown-test.js | 38 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js index 308656cc76..0a2fad6cfa 100644 --- a/src/modules/Dropdown/Dropdown.js +++ b/src/modules/Dropdown/Dropdown.js @@ -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, }) } diff --git a/test/specs/modules/Dropdown/Dropdown-test.js b/test/specs/modules/Dropdown/Dropdown-test.js index 49d8a85a8d..5a607cdefc 100644 --- a/test/specs/modules/Dropdown/Dropdown-test.js +++ b/test/specs/modules/Dropdown/Dropdown-test.js @@ -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() + + // 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' },