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();

View File

@@ -127,8 +127,8 @@
bind:value={selectedCountryItem}
bind:open={countriesOpen}
{required}
onchange={(e) => {
country = countrycodeMap[e.value.value];
onchange={(item) => {
country = countrycodeMap[item.value];
}}
onvalidate={(e) => {
countriesValid = e.detail.valid;

View File

@@ -2,11 +2,7 @@
export { default as Button } from './Button.svelte';
export { default as CenterBox } from './CenterBox.svelte';
export { default as Checkbox } from './Checkbox.svelte';
export {
default as Combobox,
type ComboboxItem,
type ComboboxChangeEvent
} from './Combobox.svelte';
export { default as Combobox, type ComboboxItem } from './Combobox.svelte';
export { default as FramelessButton } from './FramelessButton.svelte';
export { default as InjectGoogleMaps } from './InjectGoogleMaps.svelte';
export { default as InjectUmami } from './InjectUmami.svelte';