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

pressing enter after invalid search should be noop. Fixes #442 #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/components/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
evt.preventDefault()
if (instance.menu.current === null) return
const current = instance.getNode(instance.menu.current)
if (current.isBranch && instance.disableBranchNodes) return
if ((current.isBranch && instance.disableBranchNodes) || !current.isMatched) return
instance.select(current)
break
}
Expand Down
29 changes: 29 additions & 0 deletions test/unit/specs/KeyboardSupport.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ describe('Keyboard Support', () => {

wrapper.setProps({ multiple: false })

await typeSearchText(wrapper, 'a')
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([ 'a' ])
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([ 'a' ])

await typeSearchText(wrapper, 'b')
vm.setCurrentHighlightedOption(vm.forest.nodeMap.b)
expect(vm.menu.current).toBe('b')
pressEnterKey(wrapper)
Expand All @@ -139,17 +141,44 @@ describe('Keyboard Support', () => {

wrapper.setProps({ multiple: true })

await typeSearchText(wrapper, 'a')
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([ 'a' ])
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([])

await typeSearchText(wrapper, 'b')
vm.setCurrentHighlightedOption(vm.forest.nodeMap.b)
expect(vm.menu.current).toBe('b')
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([ 'b' ])
})

// https://github.com/riophae/vue-treeselect/issues/442
it('pressing enter after invalid search should be a no-op (single-select)', async () => {
const { wrapper, vm } = await createInstance()

wrapper.setProps({ multiple: false })

await typeSearchText(wrapper, 'a')
await typeSearchText(wrapper, 'ab')
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([])
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([])
})

it('pressing enter after invalid search should be a no-op (multi-select)', async () => {
const { wrapper, vm } = await createInstance()

wrapper.setProps({ multiple: true })

await typeSearchText(wrapper, 'a')
await typeSearchText(wrapper, 'ab')
pressEnterKey(wrapper)
expect(vm.internalValue).toEqual([])
})

it('pressing enter key on a disabled option should be no-op', async () => {
const { wrapper, vm } = await createInstance()

Expand Down