Skip to content

Commit

Permalink
fix: improve selectedOptions computation for multi-select with isMulti (
Browse files Browse the repository at this point in the history
  • Loading branch information
TotomInc committed Jul 22, 2024
1 parent d63ebca commit 5b58f6d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,16 @@ const availableOptions = computed(() => {
});
const selectedOptions = computed(() => {
if (props.isMulti) {
// We can safely assume it's an array due to the `isMulti` prop validation done earlier.
if (props.isMulti && Array.isArray(selected.value)) {
return (selected.value as OptionValue[]).map(
(value) => props.options.find((option) => option.value === value)!,
);
}
if (props.isMulti && !Array.isArray(selected.value)) {
console.warn(`[vue3-select-component warn]: The v-model provided should be an array when using \`isMulti\` prop, instead it was: ${selected.value}`);
}
const found = props.options.find((option) => option.value === selected.value);
return found ? [found] : [];
Expand Down

0 comments on commit 5b58f6d

Please sign in to comment.