Skip to content

Commit d2efc96

Browse files
committed
Add select on tab option and example
1 parent 867a74c commit d2efc96

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

dev/dev.html

Lines changed: 2 additions & 1 deletion
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;
@@ -68,6 +68,7 @@
6868
</span>
6969
</v-select>
7070

71+
<v-select placeholder="select on tab" :select-on-tab="true" :options="options"></v-select>
7172
<v-select placeholder="disabled" disabled value="disabled"></v-select>
7273
<v-select placeholder="disabled multiple" disabled multiple :value="['disabled', 'multiple']"></v-select>
7374
<v-select placeholder="filterable=false, @search=searchPeople" label="first_name" :filterable="false" @search="searchPeople" :options="people"></v-select>

src/components/Select.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@
329329
v-model="search"
330330
@keydown.delete="maybeDeleteValue"
331331
@keyup.esc="onEscape"
332+
@keydown.tab="onTab"
332333
@keydown.up.prevent="typeAheadUp"
333334
@keydown.down.prevent="typeAheadDown"
334335
@keydown.enter.prevent="typeAheadSelect"
@@ -346,13 +347,13 @@
346347
aria-label="Search for option"
347348
>
348349

349-
<button
350-
v-show="showClearButton"
351-
:disabled="disabled"
350+
<button
351+
v-show="showClearButton"
352+
:disabled="disabled"
352353
@click="clearSelection"
353-
type="button"
354-
class="clear"
355-
title="Clear selection"
354+
type="button"
355+
class="clear"
356+
title="Clear selection"
356357
>
357358
<span aria-hidden="true">&times;</span>
358359
</button>
@@ -680,6 +681,14 @@
680681
type: String,
681682
default: 'auto'
682683
},
684+
/**
685+
* When true, hitting the 'tab' key will select the current select value
686+
* @type {Boolean}
687+
*/
688+
selectOnTab: {
689+
type: Boolean,
690+
default: false
691+
}
683692
},
684693
685694
data() {
@@ -918,6 +927,16 @@
918927
}
919928
},
920929
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+
921940
/**
922941
* Determine if an option exists
923942
* within this.mutableOptions array.

0 commit comments

Comments
 (0)