@@ -73,7 +73,7 @@ const availableOptions = computed<GenericOption[]>(() => {
73
73
74
74
// Remove already selected values from the list of options, when in multi-select mode.
75
75
const getNonSelectedOptions = (options : GenericOption []) => options .filter (
76
- (option ) => ! (selected .value as OptionValue []) .includes (option .value ),
76
+ (option ) => Array . isArray (selected .value ) && ! selected . value .includes (option .value ),
77
77
);
78
78
79
79
if (props .isSearchable && search .value ) {
@@ -150,7 +150,12 @@ const setOption = (option: GenericOption) => {
150
150
}
151
151
152
152
if (props .isMulti ) {
153
- (selected .value as OptionValue []).push (option .value );
153
+ if (Array .isArray (selected .value )) {
154
+ selected .value .push (option .value );
155
+ }
156
+ else if (! props .disableInvalidVModelWarn ) {
157
+ console .warn (` [vue3-select-component warn]: The v-model provided should be an array when using \` isMulti\` prop, instead it was: ${selected .value } ` );
158
+ }
154
159
}
155
160
else {
156
161
selected .value = option .value ;
@@ -171,8 +176,13 @@ const setOption = (option: GenericOption) => {
171
176
172
177
const removeOption = (option : GenericOption ) => {
173
178
if (props .isMulti && ! props .isDisabled ) {
174
- selected .value = (selected .value as OptionValue []).filter ((value ) => value !== option .value );
175
- emit (" optionDeselected" , option );
179
+ if (Array .isArray (selected .value )) {
180
+ selected .value = selected .value .filter ((value ) => value !== option .value );
181
+ emit (" optionDeselected" , option );
182
+ }
183
+ else if (! props .disableInvalidVModelWarn ) {
184
+ console .warn (` [vue3-select-component warn]: The v-model provided should be an array when using \` isMulti\` prop, instead it was: ${selected .value } ` );
185
+ }
176
186
}
177
187
};
178
188
@@ -257,14 +267,14 @@ const handleNavigation = (e: KeyboardEvent) => {
257
267
closeMenu ();
258
268
}
259
269
260
- const hasSelectedValue = props .isMulti ? (selected .value as OptionValue []) .length > 0 : !! selected .value ;
270
+ const hasSelectedValue = props .isMulti && Array . isArray (selected .value ) ? selected . value .length > 0 : !! selected .value ;
261
271
262
272
// When pressing backspace with no search, remove the last selected option.
263
273
if (e .key === " Backspace" && search .value .length === 0 && hasSelectedValue ) {
264
274
e .preventDefault ();
265
275
266
- if (props .isMulti ) {
267
- selected .value = ( selected .value as OptionValue []) .slice (0 , - 1 );
276
+ if (props .isMulti && Array . isArray ( selected . value ) ) {
277
+ selected .value = selected .value .slice (0 , - 1 );
268
278
}
269
279
else {
270
280
selected .value = undefined as OptionValue ;
0 commit comments