Skip to content

Commit 04215a1

Browse files
committed
fix: improve user input management for NeCombobox
Fix a bug that prevented displaying the initial selected value if it is not included among the combo options (user input)
1 parent 752ebce commit 04215a1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/components/NeCombobox.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,18 @@ function onOptionSelected(selectedOption: NeComboboxOption) {
251251
}
252252
253253
function selectSingleOptionFromModelValue() {
254-
const optionFound = props.options.find((option) => option.id === props.modelValue)
254+
const optionFound = allOptions.value.find((option) => option.id === props.modelValue)
255255
256256
if (optionFound) {
257257
selected.value = optionFound
258+
} else if (props.acceptUserInput && props.modelValue) {
259+
const userInputOption = {
260+
id: props.modelValue as string,
261+
label: props.modelValue as string,
262+
description: props.userInputLabel
263+
}
264+
userInputOptions.value.push(userInputOption)
265+
selected.value = userInputOption
258266
}
259267
}
260268
@@ -267,6 +275,9 @@ function selectMultipleOptionsFromModelValue() {
267275
if (optionFound) {
268276
selectedList.push(optionFound)
269277
} else if (props.acceptUserInput) {
278+
if (!selectedOption.description) {
279+
selectedOption.description = props.userInputLabel
280+
}
270281
userInputOptions.value.push(selectedOption)
271282
selectedList.push(selectedOption)
272283
}

0 commit comments

Comments
 (0)