2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-10 07:52:23 +03:00

Merge remote-tracking branch 'origin/feature/input-slot' into release/v3.0

# Conflicts:
#	src/components/Select.vue
This commit is contained in:
Jeff
2019-02-16 12:05:17 -08:00
7 changed files with 175 additions and 55 deletions
+109 -31
View File
@@ -323,29 +323,9 @@
</span>
</slot>
<input
ref="search"
v-model="search"
@keydown.delete="maybeDeleteValue"
@keyup.esc="onEscape"
@keydown.up.prevent="typeAheadUp"
@keydown.down.prevent="typeAheadDown"
@keydown.enter.prevent="typeAheadSelect"
@keydown.tab="onTab"
@blur="onSearchBlur"
@focus="onSearchFocus"
type="search"
class="form-control"
:autocomplete="autocomplete"
:disabled="disabled"
:placeholder="searchPlaceholder"
:tabindex="tabindex"
:readonly="!searchable"
:id="inputId"
role="combobox"
:aria-expanded="dropdownOpen"
aria-label="Search for option"
>
<slot name="search" v-bind="scope.search">
<input v-bind="scope.search.attributes" v-on="scope.search.events">
</slot>
</div>
<div class="vs__actions">
@@ -601,7 +581,7 @@
},
/**
* Enable/disable creating options from searchInput.
* Enable/disable creating options from searchEl.
* @type {Boolean}
*/
taggable: {
@@ -732,6 +712,7 @@
type: String,
default: 'auto'
},
/**
* When true, hitting the 'tab' key will select the current select value
* @type {Boolean}
@@ -739,6 +720,20 @@
selectOnTab: {
type: Boolean,
default: false
},
/**
* Query Selector used to find the search input
* when the 'search' scoped slot is used.
*
* Must be a valid CSS selector string.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
* @type {String}
*/
searchInputQuerySelector: {
type: String,
default: '[type=search]'
}
},
@@ -805,7 +800,7 @@
*/
multiple(val) {
this.mutableValue = val ? [] : null
}
},
},
/**
@@ -892,7 +887,7 @@
onAfterSelect(option) {
if (this.closeOnSelect) {
this.open = !this.open
this.$refs.search.blur()
this.searchEl.blur()
}
if (this.clearSearchOnSelect) {
@@ -906,14 +901,14 @@
* @return {void}
*/
toggleDropdown(e) {
if (e.target === this.$refs.openIndicator || e.target === this.$refs.search || e.target === this.$refs.toggle ||
if (e.target === this.$refs.openIndicator || e.target === this.searchEl || e.target === this.$refs.toggle ||
e.target.classList.contains('selected-tag') || e.target === this.$el) {
if (this.open) {
this.$refs.search.blur() // dropdown will close on blur
this.searchEl.blur() // dropdown will close on blur
} else {
if (!this.disabled) {
this.open = true
this.$refs.search.focus()
this.searchEl.focus()
}
}
}
@@ -975,7 +970,7 @@
*/
onEscape() {
if (!this.search.length) {
this.$refs.search.blur()
this.searchEl.blur()
} else {
this.search = ''
}
@@ -1029,7 +1024,7 @@
* @return {this.value}
*/
maybeDeleteValue() {
if (!this.$refs.search.value.length && this.mutableValue && this.clearable) {
if (!this.searchEl.value.length && this.mutableValue && this.clearable) {
return this.multiple ? this.mutableValue.pop() : this.mutableValue = null
}
},
@@ -1077,11 +1072,94 @@
*/
onMousedown() {
this.mousedown = true
},
/**
* Search 'input' KeyBoardEvent handler.
* @param e {KeyboardEvent}
* @return {Function}
*/
onSearchKeyDown (e) {
switch (e.keyCode) {
case 8:
// delete
return this.maybeDeleteValue();
}
},
/**
* Search 'input' KeyBoardEvent handler.
* @param e {KeyboardEvent}
* @return {Function}
*/
onSearchKeyUp (e) {
switch (e.keyCode) {
case 27:
// esc
return this.onEscape();
case 38:
// up.prevent
e.preventDefault();
return this.typeAheadUp();
case 40:
// down.prevent
e.preventDefault();
return this.typeAheadDown();
case 13:
// enter.prevent
e.preventDefault();
return this.typeAheadSelect();
case 9:
// tab
return this.onTab();
}
}
},
computed: {
/**
* Find the search input DOM element.
* @returns {HTMLInputElement}
*/
searchEl () {
return !!this.$scopedSlots['search']
? this.$refs.selectedOptions.querySelector(this.searchInputQuerySelector)
: this.$refs.search;
},
/**
* The object to be bound to the $slots.search scoped slot.
* @returns {Object}
*/
scope () {
return {
search: {
attributes: {
'disabled': this.disabled,
'placeholder': this.searchPlaceholder,
'tabindex': this.tabindex,
'readonly': !this.searchable,
'id': this.inputId,
'aria-expanded': this.dropdownOpen,
'aria-label': 'Search for option',
'ref': 'search',
'role': 'combobox',
'type': 'search',
'autocomplete': 'off',
'class': 'form-control',
},
events: {
'keydown': this.onSearchKeyDown,
'keyup': this.onSearchKeyUp,
'blur': this.onSearchBlur,
'focus': this.onSearchFocus,
'input': (e) => this.search = e.target.value,
},
},
};
},
/**
* Classes to be output on .dropdown
* @return {Object}