Skip to content

Commit c57957c

Browse files
committed
- closes sagalbot#95
- $emit focus and blur when opening and closing the dropdown - make createOption default syntax consistent
1 parent 35e1631 commit c57957c

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/components/Select.vue

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@
191191
@keydown.up.prevent="typeAheadUp"
192192
@keydown.down.prevent="typeAheadDown"
193193
@keyup.enter.prevent="typeAheadSelect"
194-
@blur="open = false"
195-
@focus="open = true"
194+
@blur="onSearchBlur"
195+
@focus="onSearchFocus"
196196
type="search"
197197
class="form-control"
198198
:placeholder="searchPlaceholder"
@@ -382,7 +382,7 @@
382382
*/
383383
createOption: {
384384
type: Function,
385-
default: function (newOption) {
385+
default(newOption) {
386386
if (typeof this.mutableOptions[0] === 'object') {
387387
newOption = {[this.label]: newOption}
388388
}
@@ -400,6 +400,10 @@
400400
default: false
401401
},
402402
403+
/**
404+
* Disable the dropdown entirely.
405+
* @type {Boolean}
406+
*/
403407
noDrop: {
404408
type: Boolean,
405409
default: false
@@ -591,7 +595,7 @@
591595
/**
592596
* If there is any text in the search input, remove it.
593597
* Otherwise, blur the search input to close the dropdown.
594-
* @return {[type]} [description]
598+
* @return {void}
595599
*/
596600
onEscape() {
597601
if (!this.search.length) {
@@ -601,6 +605,26 @@
601605
}
602606
},
603607
608+
/**
609+
* Close the dropdown on blur.
610+
* @emits {search:blur}
611+
* @return {void}
612+
*/
613+
onSearchBlur() {
614+
this.open = false
615+
this.$emit('search:blur')
616+
},
617+
618+
/**
619+
* Open the dropdown on focus.
620+
* @emits {search:focus}
621+
* @return {void}
622+
*/
623+
onSearchFocus() {
624+
this.open = true
625+
this.$emit('search:focus')
626+
},
627+
604628
/**
605629
* Delete the value on Delete keypress when there is no
606630
* text in the search input, & there's tags to delete

0 commit comments

Comments
 (0)