Skip to content

Commit

Permalink
fix: improve user input management for NeCombobox
Browse files Browse the repository at this point in the history
Fix a bug that prevented displaying the initial selected value if it is not
included among the combo options (user input)
  • Loading branch information
andre8244 committed Jun 18, 2024
1 parent 752ebce commit 04215a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/NeCombobox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,18 @@ function onOptionSelected(selectedOption: NeComboboxOption) {
}

function selectSingleOptionFromModelValue() {
const optionFound = props.options.find((option) => option.id === props.modelValue)
const optionFound = allOptions.value.find((option) => option.id === props.modelValue)

if (optionFound) {
selected.value = optionFound
} else if (props.acceptUserInput && props.modelValue) {
const userInputOption = {
id: props.modelValue as string,
label: props.modelValue as string,
description: props.userInputLabel
}
userInputOptions.value.push(userInputOption)
selected.value = userInputOption
}
}

Expand All @@ -267,6 +275,9 @@ function selectMultipleOptionsFromModelValue() {
if (optionFound) {
selectedList.push(optionFound)
} else if (props.acceptUserInput) {
if (!selectedOption.description) {
selectedOption.description = props.userInputLabel
}
userInputOptions.value.push(selectedOption)
selectedList.push(selectedOption)
}
Expand Down

0 comments on commit 04215a1

Please sign in to comment.