Skip to content

Commit 237e946

Browse files
author
Jeff
committed
Pull onTab up to prop, add test
1 parent d2efc96 commit 237e946

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/components/Select.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,18 @@
549549
}
550550
},
551551
552+
/**
553+
* Select the current value if selectOnTab is enabled
554+
*/
555+
onTab: {
556+
type: Function,
557+
default: function () {
558+
if (this.selectOnTab) {
559+
this.typeAheadSelect();
560+
}
561+
},
562+
},
563+
552564
/**
553565
* Enable/disable creating options from searchInput.
554566
* @type {Boolean}
@@ -927,16 +939,6 @@
927939
}
928940
},
929941
930-
/**
931-
* Select the current value if selectOnTab is enabled
932-
* @return {void}
933-
*/
934-
onTab() {
935-
if (this.selectOnTab) {
936-
this.typeAheadSelect();
937-
}
938-
},
939-
940942
/**
941943
* Determine if an option exists
942944
* within this.mutableOptions array.

test/unit/specs/Select.spec.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ describe('Select.vue', () => {
109109
expect(vm.$children[0].mutableValue).toEqual(vm.value)
110110
})
111111

112+
it('can select an option on tab', (done) => {
113+
const vm = new Vue({
114+
template: `<div><v-select :options="['one','two']" select-on-tab></v-select></div>`,
115+
components: {vSelect},
116+
}).$mount()
117+
118+
vm.$children[0].typeAheadPointer = 0
119+
120+
trigger(vm.$children[0].$refs.search, 'keydown', (e) => e.keyCode = 9)
121+
122+
Vue.nextTick(() => {
123+
expect(vm.$children[0].mutableValue).toEqual('one');
124+
done();
125+
})
126+
})
127+
112128
it('can deselect a pre-selected object', () => {
113129
const vm = new Vue({
114130
template: '<div><v-select :options="options" :value="value" :multiple="true"></v-select></div>',
@@ -1377,7 +1393,7 @@ describe('Select.vue', () => {
13771393
value: 'foo'
13781394
}
13791395
}).$mount()
1380-
1396+
13811397
expect(vm.mutableValue).toEqual('foo')
13821398
vm.$el.querySelector( 'button.clear' ).click()
13831399
expect(vm.mutableValue).toEqual(null)
@@ -1396,6 +1412,6 @@ describe('Select.vue', () => {
13961412
const buttonEl = vm.$el.querySelector( 'button.clear' )
13971413
expect(buttonEl.disabled).toEqual(true);
13981414
})
1399-
1415+
14001416
});
14011417
})

0 commit comments

Comments
 (0)