-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Select.vue
1373 lines (1260 loc) · 34.8 KB
/
Select.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<style>
@import '../css/vue-select.css';
</style>
<template>
<div :dir="dir" class="v-select" :class="stateClasses">
<slot name="header" v-bind="scope.header" />
<div
:id="`vs${uid}__combobox`"
ref="toggle"
class="vs__dropdown-toggle"
role="combobox"
:aria-expanded="dropdownOpen.toString()"
:aria-owns="`vs${uid}__listbox`"
aria-label="Search for option"
@mousedown="toggleDropdown($event)"
>
<div ref="selectedOptions" class="vs__selected-options">
<slot
v-for="option in selectedValue"
name="selected-option-container"
:option="normalizeOptionForSlot(option)"
:deselect="deselect"
:multiple="multiple"
:disabled="disabled"
>
<span :key="getOptionKey(option)" class="vs__selected">
<slot
name="selected-option"
v-bind="normalizeOptionForSlot(option)"
>
{{ getOptionLabel(option) }}
</slot>
<button
v-if="multiple"
ref="deselectButtons"
:disabled="disabled"
type="button"
class="vs__deselect"
:title="`Deselect ${getOptionLabel(option)}`"
:aria-label="`Deselect ${getOptionLabel(option)}`"
@click="deselect(option)"
>
<component :is="childComponents.Deselect" />
</button>
</span>
</slot>
<slot name="search" v-bind="scope.search">
<input
class="vs__search"
v-bind="scope.search.attributes"
v-on="scope.search.events"
/>
</slot>
</div>
<div ref="actions" class="vs__actions">
<button
v-show="showClearButton"
ref="clearButton"
:disabled="disabled"
type="button"
class="vs__clear"
title="Clear Selected"
aria-label="Clear Selected"
@click="clearSelection"
>
<component :is="childComponents.Deselect" />
</button>
<slot name="open-indicator" v-bind="scope.openIndicator">
<component
:is="childComponents.OpenIndicator"
v-if="!noDrop"
v-bind="scope.openIndicator.attributes"
/>
</slot>
<slot name="spinner" v-bind="scope.spinner">
<div v-show="mutableLoading" class="vs__spinner">Loading...</div>
</slot>
</div>
</div>
<transition :name="transition">
<ul
v-if="dropdownOpen"
:id="`vs${uid}__listbox`"
ref="dropdownMenu"
:key="`vs${uid}__listbox`"
v-append-to-body
class="vs__dropdown-menu"
role="listbox"
tabindex="-1"
@mousedown.prevent="onMousedown"
@mouseup="onMouseUp"
>
<slot name="list-header" v-bind="scope.listHeader" />
<li
v-for="(option, index) in filteredOptions"
:id="`vs${uid}__option-${index}`"
:key="getOptionKey(option)"
role="option"
class="vs__dropdown-option"
:class="{
'vs__dropdown-option--deselect':
isOptionDeselectable(option) && index === typeAheadPointer,
'vs__dropdown-option--selected': isOptionSelected(option),
'vs__dropdown-option--highlight': index === typeAheadPointer,
'vs__dropdown-option--disabled': !selectable(option),
}"
:aria-selected="index === typeAheadPointer ? true : null"
@mouseover="selectable(option) ? (typeAheadPointer = index) : null"
@click.prevent.stop="selectable(option) ? select(option) : null"
>
<slot name="option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
</li>
<li v-if="filteredOptions.length === 0" class="vs__no-options">
<slot name="no-options" v-bind="scope.noOptions">
Sorry, no matching options.
</slot>
</li>
<slot name="list-footer" v-bind="scope.listFooter" />
</ul>
<ul
v-else
:id="`vs${uid}__listbox`"
role="listbox"
style="display: none; visibility: hidden"
></ul>
</transition>
<slot name="footer" v-bind="scope.footer" />
</div>
</template>
<script>
import pointerScroll from '../mixins/pointerScroll.js'
import typeAheadPointer from '../mixins/typeAheadPointer.js'
import ajax from '../mixins/ajax.js'
import childComponents from './childComponents.js'
import appendToBody from '../directives/appendToBody.js'
import sortAndStringify from '../utility/sortAndStringify.js'
import uniqueId from '../utility/uniqueId.js'
/**
* @name VueSelect
*/
export default {
components: { ...childComponents },
directives: { appendToBody },
mixins: [pointerScroll, typeAheadPointer, ajax],
props: {
/**
* Contains the currently selected value. Very similar to a
* `value` attribute on an <input>. You can listen for changes
* with the 'input' event.
* @type {Object||String||null}
*/
// eslint-disable-next-line vue/require-default-prop,vue/require-prop-types
value: {},
/**
* An object with any custom components that you'd like to overwrite
* the default implementation of in your app. The keys in this object
* will be merged with the defaults.
* @see https://vue-select.org/guide/components.html
* @type {Function}
*/
components: {
type: Object,
default: () => ({}),
},
/**
* An array of strings or objects to be used as dropdown choices.
* If you are using an array of objects, vue-select will look for
* a `label` key (ex. [{label: 'This is Foo', value: 'foo'}]). A
* custom label key can be set with the `label` prop.
* @type {Array}
*/
options: {
type: Array,
default() {
return []
},
},
/**
* Disable the entire component.
* @type {Boolean}
*/
disabled: {
type: Boolean,
default: false,
},
/**
* Can the user clear the selected property.
* @type {Boolean}
*/
clearable: {
type: Boolean,
default: true,
},
/**
* Can the user deselect an option by clicking it from
* within the dropdown.
* @type {Boolean}
*/
deselectFromDropdown: {
type: Boolean,
default: false,
},
/**
* Enable/disable filtering the options.
* @type {Boolean}
*/
searchable: {
type: Boolean,
default: true,
},
/**
* Equivalent to the `multiple` attribute on a `<select>` input.
* @type {Boolean}
*/
multiple: {
type: Boolean,
default: false,
},
/**
* Equivalent to the `placeholder` attribute on an `<input>`.
* @type {String}
*/
placeholder: {
type: String,
default: '',
},
/**
* Sets a Vue transition property on the `.vs__dropdown-menu`.
* @type {String}
*/
transition: {
type: String,
default: 'vs__fade',
},
/**
* Enables/disables clearing the search text when an option is selected.
* @type {Boolean}
*/
clearSearchOnSelect: {
type: Boolean,
default: true,
},
/**
* Close a dropdown when an option is chosen. Set to false to keep the dropdown
* open (useful when combined with multi-select, for example)
* @type {Boolean}
*/
closeOnSelect: {
type: Boolean,
default: true,
},
/**
* Tells vue-select what key to use when generating option
* labels when each `option` is an object.
* @type {String}
*/
label: {
type: String,
default: 'label',
},
/**
* Value of the 'autocomplete' field of the input
* element.
* @type {String}
*/
autocomplete: {
type: String,
default: 'off',
},
/**
* When working with objects, the reduce
* prop allows you to transform a given
* object to only the information you
* want passed to a v-model binding
* or @input event.
*/
reduce: {
type: Function,
default: (option) => option,
},
/**
* Decides whether an option is selectable or not. Not selectable options
* are displayed but disabled and cannot be selected.
*
* @type {Function}
* @since 3.3.0
* @param {Object|String} option
* @return {Boolean}
*/
selectable: {
type: Function,
default: (option) => true,
},
/**
* Callback to generate the label text. If {option}
* is an object, returns option[this.label] by default.
*
* Label text is used for filtering comparison and
* displaying. If you only need to adjust the
* display, you should use the `option` and
* `selected-option` slots.
*
* @type {Function}
* @param {Object || String} option
* @return {String}
*/
getOptionLabel: {
type: Function,
default(option) {
if (typeof option === 'object') {
if (!option.hasOwnProperty(this.label)) {
return console.warn(
`[vue-select warn]: Label key "option.${this.label}" does not` +
` exist in options object ${JSON.stringify(option)}.\n` +
'https://vue-select.org/api/props.html#getoptionlabel'
)
}
return option[this.label]
}
return option
},
},
/**
* Generate a unique identifier for each option. If `option`
* is an object and `option.hasOwnProperty('id')` exists,
* `option.id` is used by default, otherwise the option
* will be serialized to JSON.
*
* If you are supplying a lot of options, you should
* provide your own keys, as JSON.stringify can be
* slow with lots of objects.
*
* The result of this function *must* be unique.
*
* @type {Function}
* @param {Object || String} option
* @return {String}
*/
getOptionKey: {
type: Function,
default(option) {
if (typeof option !== 'object') {
return option
}
try {
return option.hasOwnProperty('id')
? option.id
: sortAndStringify(option)
} catch (e) {
const warning =
`[vue-select warn]: Could not stringify this 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'
return console.warn(warning, option, e)
}
},
},
/**
* Select the current value if selectOnTab is enabled
* @deprecated since 3.3
*/
onTab: {
type: Function,
default: function () {
if (this.selectOnTab && !this.isComposing) {
this.typeAheadSelect()
}
},
},
/**
* Enable/disable creating options from searchEl.
* @type {Boolean}
*/
taggable: {
type: Boolean,
default: false,
},
/**
* Set the tabindex for the input field.
* @type {Number}
*/
tabindex: {
type: Number,
default: null,
},
/**
* When true, newly created tags will be added to
* the options list.
* @type {Boolean}
*/
pushTags: {
type: Boolean,
default: false,
},
/**
* When true, existing options will be filtered
* by the search text. Should not be used in conjunction
* with taggable.
* @type {Boolean}
*/
filterable: {
type: Boolean,
default: true,
},
/**
* Callback to determine if the provided option should
* match the current search text. Used to determine
* if the option should be displayed.
* @type {Function}
* @param {Object || String} option
* @param {String} label
* @param {String} search
* @return {Boolean}
*/
filterBy: {
type: Function,
default(option, label, search) {
return (
(label || '')
.toLocaleLowerCase()
.indexOf(search.toLocaleLowerCase()) > -1
)
},
},
/**
* Callback to filter results when search text
* is provided. Default implementation loops
* each option, and returns the result of
* this.filterBy.
* @type {Function}
* @param {Array} list of options
* @param {String} search text
* @param {Object} vSelect instance
* @return {Boolean}
*/
filter: {
type: Function,
default(options, search) {
return options.filter((option) => {
let label = this.getOptionLabel(option)
if (typeof label === 'number') {
label = label.toString()
}
return this.filterBy(option, label, search)
})
},
},
/**
* User defined function for adding Options
* @type {Function}
*/
createOption: {
type: Function,
default(option) {
return typeof this.optionList[0] === 'object'
? { [this.label]: option }
: option
},
},
/**
* When false, updating the options will not reset the selected value. Accepts
* a `boolean` or `function` that returns a `boolean`. If defined as a function,
* it will receive the params listed below.
*
* @since 3.4 - Type changed to {Boolean|Function}
*
* @type {Boolean|Function}
* @param {Array} newOptions
* @param {Array} oldOptions
* @param {Array} selectedValue
*/
resetOnOptionsChange: {
default: false,
validator: (value) => ['function', 'boolean'].includes(typeof value),
},
/**
* If search text should clear on blur
* @return {Boolean} True when single and clearSearchOnSelect
*/
clearSearchOnBlur: {
type: Function,
default: function ({ clearSearchOnSelect, multiple }) {
return clearSearchOnSelect && !multiple
},
},
/**
* Disable the dropdown entirely.
* @type {Boolean}
*/
noDrop: {
type: Boolean,
default: false,
},
/**
* Sets the id of the input element.
* @type {String}
* @default {null}
*/
// eslint-disable-next-line vue/require-default-prop
inputId: {
type: String,
},
/**
* Sets RTL support. Accepts 'ltr', 'rtl', 'auto'.
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir
* @type {String}
* @default 'auto'
*/
dir: {
type: String,
default: 'auto',
},
/**
* 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: () => [
// enter
13,
],
},
/**
* 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]',
},
/**
* 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,
},
/**
* Append the dropdown element to the end of the body
* and size/position it dynamically. Use it if you have
* overflow or z-index issues.
* @type {Boolean}
*/
appendToBody: {
type: Boolean,
default: false,
},
/**
* When `appendToBody` is true, this function is responsible for
* positioning the drop down list.
*
* If a function is returned from `calculatePosition`, it will
* be called when the drop down list is removed from the DOM.
* This allows for any garbage collection you may need to do.
*
* @since v3.7.0
* @see http://vue-select.org/guide/positioning.html
*/
calculatePosition: {
type: Function,
/**
* @param dropdownList {HTMLUListElement}
* @param component {Vue} current instance of vue select
* @param width {string} calculated width in pixels of the dropdown menu
* @param top {string} absolute position top value in pixels relative to the document
* @param left {string} absolute position left value in pixels relative to the document
* @return {function|void}
*/
default(dropdownList, component, { width, top, left }) {
dropdownList.style.top = top
dropdownList.style.left = left
dropdownList.style.width = width
},
},
/**
* Determines whether the dropdown should be open.
* Receives the component instance as the only argument.
*
* @since v3.12.0
* @return boolean
*/
dropdownShouldOpen: {
type: Function,
default({ noDrop, open, mutableLoading }) {
return noDrop ? false : open && !mutableLoading
},
},
/**
* A unique identifier used to generate IDs in HTML.
* Must be unique for every instance of the component.
*/
uid: {
type: [String, Number],
default: () => uniqueId(),
},
},
data() {
return {
search: '',
open: false,
isComposing: false,
pushedTags: [],
// eslint-disable-next-line vue/no-reserved-keys
_value: [], // Internal value managed by Vue Select if no `value` prop is passed
}
},
computed: {
/**
* Determine if the component needs to
* track the state of values internally.
* @return {boolean}
*/
isTrackingValues() {
return (
typeof this.value === 'undefined' ||
this.$options.propsData.hasOwnProperty('reduce')
)
},
/**
* The options that are currently selected.
* @return {Array}
*/
selectedValue() {
let value = this.value
if (this.isTrackingValues) {
// Vue select has to manage value internally
value = this.$data._value
}
if (value !== undefined && value !== null && value !== '') {
return [].concat(value)
}
return []
},
/**
* The options available to be chosen
* from the dropdown, including any
* tags that have been pushed.
*
* @return {Array}
*/
optionList() {
return this.options.concat(this.pushTags ? this.pushedTags : [])
},
/**
* 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() {
const listSlot = {
search: this.search,
loading: this.loading,
searching: this.searching,
filteredOptions: this.filteredOptions,
}
return {
search: {
attributes: {
disabled: this.disabled,
placeholder: this.searchPlaceholder,
tabindex: this.tabindex,
readonly: !this.searchable,
id: this.inputId,
'aria-autocomplete': 'list',
'aria-labelledby': `vs${this.uid}__combobox`,
'aria-controls': `vs${this.uid}__listbox`,
ref: 'search',
type: 'search',
autocomplete: this.autocomplete,
value: this.search,
...(this.dropdownOpen && this.filteredOptions[this.typeAheadPointer]
? {
'aria-activedescendant': `vs${this.uid}__option-${this.typeAheadPointer}`,
}
: {}),
},
events: {
compositionstart: () => (this.isComposing = true),
compositionend: () => (this.isComposing = false),
keydown: this.onSearchKeyDown,
keypress: this.onSearchKeyPress,
blur: this.onSearchBlur,
focus: this.onSearchFocus,
input: (e) => (this.search = e.target.value),
},
},
spinner: {
loading: this.mutableLoading,
},
noOptions: {
search: this.search,
loading: this.mutableLoading,
searching: this.searching,
},
openIndicator: {
attributes: {
ref: 'openIndicator',
role: 'presentation',
class: 'vs__open-indicator',
},
},
listHeader: listSlot,
listFooter: listSlot,
header: { ...listSlot, deselect: this.deselect },
footer: { ...listSlot, deselect: this.deselect },
}
},
/**
* Returns an object containing the child components
* that will be used throughout the component. The
* `component` prop can be used to overwrite the defaults.
*
* @return {Object}
*/
childComponents() {
return {
...childComponents,
...this.components,
}
},
/**
* Holds the current state of the component.
* @return {Object}
*/
stateClasses() {
return {
'vs--open': this.dropdownOpen,
'vs--single': !this.multiple,
'vs--multiple': this.multiple,
'vs--searching': this.searching && !this.noDrop,
'vs--searchable': this.searchable && !this.noDrop,
'vs--unsearchable': !this.searchable,
'vs--loading': this.mutableLoading,
'vs--disabled': this.disabled,
}
},
/**
* Return the current state of the
* search input
* @return {Boolean} True if non empty value
*/
searching() {
return !!this.search
},
/**
* Return the current state of the
* dropdown menu.
* @return {Boolean} True if open
*/
dropdownOpen() {
return this.dropdownShouldOpen(this)
},
/**
* Return the placeholder string if it's set
* & there is no value selected.
* @return {String} Placeholder text
*/
searchPlaceholder() {
return this.isValueEmpty && this.placeholder
? this.placeholder
: undefined
},
/**
* The currently displayed options, filtered
* by the search elements value. If tagging
* true, the search text will be prepended
* if it doesn't already exist.
*
* @return {array}
*/
filteredOptions() {
const optionList = [].concat(this.optionList)
if (!this.filterable && !this.taggable) {
return optionList
}
let options = this.search.length
? this.filter(optionList, this.search, this)
: optionList
if (this.taggable && this.search.length) {
const createdOption = this.createOption(this.search)
if (!this.optionExists(createdOption)) {
options.unshift(createdOption)
}
}
return options
},
/**
* Check if there aren't any options selected.
* @return {Boolean}
*/
isValueEmpty() {
return this.selectedValue.length === 0
},
/**
* Determines if the clear button should be displayed.
* @return {Boolean}
*/
showClearButton() {
return (
!this.multiple && this.clearable && !this.open && !this.isValueEmpty
)
},
},
watch: {
/**
* Maybe reset the value
* when options change.
* Make sure selected option
* is correct.
* @return {[type]} [description]
*/
options(newOptions, oldOptions) {
let shouldReset = () =>
typeof this.resetOnOptionsChange === 'function'
? this.resetOnOptionsChange(
newOptions,
oldOptions,
this.selectedValue
)
: this.resetOnOptionsChange
if (!this.taggable && shouldReset()) {
this.clearSelection()
}
if (this.value && this.isTrackingValues) {
this.setInternalValueFromOptions(this.value)
}
},
/**
* Make sure to update internal
* value if prop changes outside
*/
value: {
immediate: true,
handler(val) {
if (this.isTrackingValues) {
this.setInternalValueFromOptions(val)
}
},
},
/**
* Always reset the value when
* the multiple prop changes.
* @return {void}
*/
multiple() {
this.clearSelection()
},
open(isOpen) {
this.$emit(isOpen ? 'open' : 'close')
},
search(search) {
if (search.length) {
this.open = true
}
},
},
created() {
this.mutableLoading = this.loading
this.$on('option:created', this.pushTag)
},
methods: {
/**
* Make sure tracked value is
* one option if possible.
* @param {Object|String} value
* @return {void}
*/
setInternalValueFromOptions(value) {
if (Array.isArray(value)) {
this.$data._value = value.map((val) =>
this.findOptionFromReducedValue(val)
)
} else {
this.$data._value = this.findOptionFromReducedValue(value)
}
},
/**
* Select or deselect a given option.
* Allow deselect if clearable or if not the only selected option.
* @param {Object|String} option
* @return {void}
*/
select(option) {
this.$emit('option:selecting', option)
if (!this.isOptionSelected(option)) {
if (this.taggable && !this.optionExists(option)) {