From 5baaa767bf3207307846b080e527b1ca7c2b78fe Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 19 Jan 2023 18:57:23 -0800 Subject: [PATCH] Fix dropdown not opening after closing Signed-off-by: Christopher Ng --- src/components/Select.vue | 4 ++++ tests/unit/Dropdown.spec.js | 9 +++++++++ tests/unit/Keydown.spec.js | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/components/Select.vue b/src/components/Select.vue index a4efc86e2..2dbc8e72c 100644 --- a/src/components/Select.vue +++ b/src/components/Select.vue @@ -1317,6 +1317,10 @@ export default { onSearchKeyDown(e) { const preventAndSelect = (e) => { e.preventDefault() + if (!this.open) { + this.open = true + return + } return !this.isComposing && this.typeAheadSelect() } diff --git a/tests/unit/Dropdown.spec.js b/tests/unit/Dropdown.spec.js index ef3721be3..db93ba4d3 100755 --- a/tests/unit/Dropdown.spec.js +++ b/tests/unit/Dropdown.spec.js @@ -63,6 +63,15 @@ describe('Toggling Dropdown', () => { expect(Select.vm.search).toEqual('') }) + it('should open dropdown on selectOnKeyCodes keydown', async () => { + const Select = mountDefault() + const input = Select.findComponent({ ref: 'search' }) + + input.trigger('keydown.enter') + + expect(Select.vm.open).toEqual(true) + }) + it('should open dropdown on alphabetic input', async () => { const Select = mountDefault() const input = Select.findComponent({ ref: 'search' }) diff --git a/tests/unit/Keydown.spec.js b/tests/unit/Keydown.spec.js index e46eb494f..0b91e83ce 100644 --- a/tests/unit/Keydown.spec.js +++ b/tests/unit/Keydown.spec.js @@ -19,6 +19,7 @@ describe('Custom Keydown Handlers', () => { const spy = jest.spyOn(Select.vm, 'typeAheadSelect') + Select.vm.open = true Select.findComponent({ ref: 'search' }).trigger('keydown.space') expect(spy).toHaveBeenCalledTimes(1) @@ -33,6 +34,7 @@ describe('Custom Keydown Handlers', () => { const spy = jest.spyOn(Select.vm, 'typeAheadSelect') + Select.vm.open = true Select.findComponent({ ref: 'search' }).trigger('keydown.space') expect(onKeyDown.mock.calls.length).toBe(1)