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 <[email protected]>
  • Loading branch information
Pytal committed Jan 20, 2023
1 parent 8577536 commit 5baaa76
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 5baaa76

Please sign in to comment.