Skip to content

Commit 0eb0e2c

Browse files
committed
feat(select): automatically convert v-model to array when undefined with is-multi
#212
1 parent 3ccbe10 commit 0eb0e2c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: src/Select.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ const emit = defineEmits<{
4444
(e: "search", value: string): void;
4545
}>();
4646
47-
const selected = defineModel<OptionValue | OptionValue[]>({
48-
required: true,
49-
validator: (value, _props) => _props.isMulti ? Array.isArray(value) : !Array.isArray(value),
50-
});
47+
const selected = defineModel<OptionValue | OptionValue[]>({ required: true });
5148
5249
const containerRef = useTemplateRef("container");
5350
const inputRef = useTemplateRef("input");
@@ -154,8 +151,12 @@ const setOption = (option: GenericOption) => {
154151
if (Array.isArray(selected.value)) {
155152
selected.value.push(option.value);
156153
}
157-
else if (!props.disableInvalidVModelWarn) {
158-
console.warn(`[vue3-select-component warn]: The v-model provided should be an array when using \`isMulti\` prop, instead it was: ${selected.value}`);
154+
else {
155+
selected.value = [option.value];
156+
157+
if (!props.disableInvalidVModelWarn) {
158+
console.warn(`[vue3-select-component warn]: The v-model provided should be an array when using \`isMulti\` prop, instead it was: ${selected.value}. Since an option has been selected, the component automatically converted the v-model to an array.`);
159+
}
159160
}
160161
}
161162
else {

0 commit comments

Comments
 (0)