simplify combobox event type

This commit is contained in:
Elijah Duffy
2025-07-03 15:23:39 -07:00
parent 881d29562e
commit 8bea47f9fd
3 changed files with 6 additions and 14 deletions

View File

@@ -9,10 +9,6 @@
render?: Snippet<[item: ComboboxItem]>;
};
export type ComboboxChangeEvent = {
value: ComboboxItem;
};
const getLabel = (item: ComboboxItem | undefined): string => item?.label ?? item?.value ?? '';
const getPreview = (item: ComboboxItem | undefined): string => item?.preview ?? getLabel(item);
</script>
@@ -45,7 +41,7 @@
notFoundMessage?: string;
class?: ClassValue | null | undefined;
onvalidate?: (e: InputValidatorEvent) => void;
onchange?: (e: ComboboxChangeEvent) => void;
onchange?: (item: ComboboxItem) => void;
}
let {
@@ -291,7 +287,7 @@
value = item;
open = false;
searchInput?.focus();
onchange?.({ value: item });
onchange?.(item);
}}
onkeydown={() => {}}
tabindex="-1"
@@ -398,7 +394,7 @@
if (e.key === 'Tab' || e.key === 'Enter') {
if (open && highlighted && highlighted.value !== value?.value) {
value = highlighted;
onchange?.({ value: highlighted });
onchange?.(highlighted);
}
if (e.key === 'Enter') {
e.preventDefault();