Skip to content

Commit

Permalink
Fix dropdown not opening after closing
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jan 20, 2023
1 parent 8577536 commit 9969152
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/Select.vue
Expand Up @@ -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()
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/Dropdown.spec.js
Expand Up @@ -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' })
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Keydown.spec.js
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 9969152

Please sign in to comment.