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

Merge branch 'master' into 975-dropdown-option-slot-overhaul

# Conflicts:
#	dev/Dev.vue
#	src/components/Select.vue
This commit is contained in:
Jeff
2019-11-11 18:27:58 -08:00
13 changed files with 396 additions and 40 deletions
+69 -32
View File
@@ -20,7 +20,7 @@
</slot>
</div>
<div class="vs__actions">
<div class="vs__actions" ref="actions">
<slot name="clear">
<component
:is="scope.clear.component"
@@ -69,6 +69,9 @@
import ajax from '../mixins/ajax'
import childComponents from './childComponents';
/**
* @name VueSelect
*/
export default {
components: {...childComponents},
@@ -282,7 +285,7 @@
`[vue-select warn]: Could not stringify option ` +
`to generate unique key. Please provide'getOptionKey' prop ` +
`to return a unique key for each option.\n` +
'https://vue-select.org/api/props.html#getoptionkey',
'https://vue-select.org/api/props.html#getoptionkey'
);
}
}
@@ -364,11 +367,12 @@
/**
* Select the current value if selectOnTab is enabled
* @deprecated since 3.3
*/
onTab: {
type: Function,
default: function () {
if (this.selectOnTab) {
if (this.selectOnTab && !this.isComposing) {
this.typeAheadSelect();
}
},
@@ -460,14 +464,9 @@
*/
createOption: {
type: Function,
default(newOption) {
if (typeof this.optionList[0] === 'object') {
newOption = {[this.label]: newOption}
}
this.$emit('option:created', newOption)
return newOption
}
default (option) {
return (typeof this.optionList[0] === 'object') ? {[this.label]: option} : option;
},
},
/**
@@ -511,12 +510,22 @@
/**
* When true, hitting the 'tab' key will select the current select value
* @type {Boolean}
* @deprecated since 3.3 - use selectOnKeyCodes instead
*/
selectOnTab: {
type: Boolean,
default: false
},
/**
* Keycodes that will select the current option.
* @type Array
*/
selectOnKeyCodes: {
type: Array,
default: () => [13],
},
/**
* Query Selector used to find the search input
* when the 'search' scoped slot is used.
@@ -529,6 +538,21 @@
searchInputQuerySelector: {
type: String,
default: '[type=search]'
},
/**
* Used to modify the default keydown events map
* for the search input. Can be used to implement
* custom behaviour for key presses.
*/
mapKeydown: {
type: Function,
/**
* @param map {Object}
* @param vm {VueSelect}
* @return {Object}
*/
default: (map, vm) => map,
}
},
@@ -536,6 +560,7 @@
return {
search: '',
open: false,
isComposing: false,
pushedTags: [],
_value: [] // Internal value managed by Vue Select if no `value` prop is passed
}
@@ -613,7 +638,8 @@
select(option) {
if (!this.isOptionSelected(option)) {
if (this.taggable && !this.optionExists(option)) {
option = this.createOption(option)
option = this.createOption(option);
this.$emit('option:created', option);
}
if (this.multiple) {
option = this.selectedValue.concat(option)
@@ -695,6 +721,8 @@
this.$el,
this.searchEl,
this.$refs.toggle,
this.$refs.actions,
this.$refs.selectedOptions,
];
if (typeof this.$refs.openIndicator !== 'undefined') {
@@ -902,39 +930,46 @@
},
/**
* Search 'input' KeyBoardEvent handler.
* Search <input> KeyBoardEvent handler.
* @param e {KeyboardEvent}
* @return {Function}
*/
onSearchKeyDown (e) {
switch (e.keyCode) {
case 8:
// delete
return this.maybeDeleteValue();
case 9:
// tab
return this.onTab();
case 13:
// enter.prevent
e.preventDefault();
return this.typeAheadSelect();
case 27:
// esc
return this.onEscape();
case 38:
// up.prevent
const preventAndSelect = e => {
e.preventDefault();
return !this.isComposing && this.typeAheadSelect();
};
const defaults = {
// delete
8: e => this.maybeDeleteValue(),
// tab
9: e => this.onTab(),
// esc
27: e => this.onEscape(),
// up.prevent
38: e => {
e.preventDefault();
return this.typeAheadUp();
case 40:
// down.prevent
},
// down.prevent
40: e => {
e.preventDefault();
return this.typeAheadDown();
},
};
this.selectOnKeyCodes.forEach(keyCode => defaults[keyCode] = preventAndSelect);
const handlers = this.mapKeydown(defaults, this);
if (typeof handlers[e.keyCode] === 'function') {
return handlers[e.keyCode](e);
}
}
},
computed: {
/**
* Determine if the component needs to
* track the state of values internally.
@@ -1018,6 +1053,8 @@
'value': this.search,
},
events: {
'compositionstart': () => this.isComposing = true,
'compositionend': () => this.isComposing = false,
'keydown': this.onSearchKeyDown,
'blur': this.onSearchBlur,
'focus': this.onSearchFocus,