Skip to content

Commit e8e5eff

Browse files
author
Jeff
committed
Merge branch 'kball-add-select-on-tab-option'
# Conflicts: # src/components/Select.vue
2 parents 6866dee + 237e946 commit e8e5eff

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

dev/dev.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">-->
1010
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css">-->
1111
<style>
12-
12+
1313
#app {
1414
height: 95vh;
1515
display: flex;
@@ -67,7 +67,7 @@
6767
</button>
6868
</span>
6969
</v-select>
70-
70+
<v-select placeholder="select on tab" :select-on-tab="true" :options="options"></v-select>
7171
<v-select placeholder="disabled" disabled value="disabled"></v-select>
7272
<v-select placeholder="disabled multiple" disabled multiple :value="['disabled', 'multiple']"></v-select>
7373
<v-select placeholder="filterable=false, @search=searchPeople" label="first_name" :filterable="false" @search="searchPeople" :options="people"></v-select>

src/components/Select.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
@keydown.up.prevent="typeAheadUp"
340340
@keydown.down.prevent="typeAheadDown"
341341
@keydown.enter.prevent="typeAheadSelect"
342+
@keydown.tab="onTab"
342343
@blur="onSearchBlur"
343344
@focus="onSearchFocus"
344345
type="search"
@@ -578,6 +579,18 @@
578579
}
579580
},
580581
582+
/**
583+
* Select the current value if selectOnTab is enabled
584+
*/
585+
onTab: {
586+
type: Function,
587+
default: function () {
588+
if (this.selectOnTab) {
589+
this.typeAheadSelect();
590+
}
591+
},
592+
},
593+
581594
/**
582595
* Enable/disable creating options from searchInput.
583596
* @type {Boolean}
@@ -710,6 +723,14 @@
710723
type: String,
711724
default: 'auto'
712725
},
726+
/**
727+
* When true, hitting the 'tab' key will select the current select value
728+
* @type {Boolean}
729+
*/
730+
selectOnTab: {
731+
type: Boolean,
732+
default: false
733+
}
713734
},
714735
715736
data() {

test/unit/specs/Select.spec.js

Lines changed: 16 additions & 0 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>',

0 commit comments

Comments
 (0)