diff --git a/src/components/NeCombobox.vue b/src/components/NeCombobox.vue index 5e21bfb..7915703 100644 --- a/src/components/NeCombobox.vue +++ b/src/components/NeCombobox.vue @@ -14,7 +14,10 @@ import { ComboboxOptions } from '@headlessui/vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' -import { faChevronDown as fasChevronDown } from '@fortawesome/free-solid-svg-icons' +import { + faChevronDown as fasChevronDown, + type IconDefinition +} from '@fortawesome/free-solid-svg-icons' import { faCheck as fasCheck } from '@fortawesome/free-solid-svg-icons' import { faXmark as fasXmark } from '@fortawesome/free-solid-svg-icons' import NeBadge from './NeBadge.vue' @@ -25,6 +28,7 @@ export interface NeComboboxOption { id: string label: string description?: string + icon?: IconDefinition rawObj?: any disabled?: boolean } @@ -251,10 +255,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 } } @@ -267,6 +279,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) } @@ -361,10 +376,19 @@ onClickOutside(comboboxRef, () => onClickOutsideCombobox()) : 'text-gray-900 dark:text-gray-100' ]" > -
- +
+ +