diff --git a/resources/js/components/ComboBox/ComboBox.vue b/resources/js/components/ComboBox/ComboBox.vue index 0f7f0661..b40444ee 100644 --- a/resources/js/components/ComboBox/ComboBox.vue +++ b/resources/js/components/ComboBox/ComboBox.vue @@ -324,7 +324,19 @@ function handleKeyDown(event: KeyboardEvent) { } watch(query, () => { - highlightedOption.value = first(filteredOptions.value) ?? null; + if (!props.modelValue) { + highlightedOption.value = first(filteredOptions.value) ?? null; + } + + // if the current selected item is in the filtered options, + // use it as the default highlighted option + const isModelValueInFilteredOptions = filteredOptions.value.some((option) => + areOptionsEqual(option, props.modelValue), + ); + + highlightedOption.value = isModelValueInFilteredOptions + ? props.modelValue + : first(filteredOptions.value) ?? null; }); const { floatingStyles } = useFloating(