Skip to content

Commit

Permalink
fix: default highlighted should be the current selected if query allo…
Browse files Browse the repository at this point in the history
…ws it
  • Loading branch information
jxjj committed Sep 23, 2024
1 parent b9ff464 commit ca0eccb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion resources/js/components/ComboBox/ComboBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ca0eccb

Please sign in to comment.