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

fix(1213): Skip selecting on tab if component is not open #1787

Open
wants to merge 3 commits 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/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export default {
onTab: {
type: Function,
default: function () {
if (this.selectOnTab && !this.isComposing) {
if (this.selectOnTab && !this.isComposing && this.open) {
this.typeAheadSelect()
}
},
Expand Down
21 changes: 19 additions & 2 deletions tests/unit/Selecting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('VS - Selecting Values', () => {
expect(Select.selectedValue).toEqual(Select.value)
})

it('can select an option on tab', () => {
it('can select an option on tab while open', async () => {
const Select = shallowMount(VueSelect, {
propsData: {
selectOnTab: true,
Expand All @@ -59,9 +59,26 @@ describe('VS - Selecting Values', () => {

const spy = jest.spyOn(Select.vm, 'typeAheadSelect')

Select.findComponent({ ref: 'search' }).trigger('focus');
Select.findComponent({ ref: 'search' }).trigger('keydown.tab')

expect(spy).toHaveBeenCalledWith()
expect(spy).toHaveBeenCalledTimes(1);
})

it('cannot select an option on tab while closed', async () => {
const Select = shallowMount(VueSelect, {
propsData: {
selectOnTab: true,
},
})

const spy = jest.spyOn(Select.vm, 'typeAheadSelect')

Select.findComponent({ ref: 'search' }).trigger('focus');
Select.findComponent({ ref: 'search' }).trigger('blur');
Select.findComponent({ ref: 'search' }).trigger('keydown.tab')

expect(spy).toHaveBeenCalledTimes(0);
})

it('can deselect a pre-selected object', () => {
Expand Down