simplify combobox event type
This commit is contained in:
@@ -9,10 +9,6 @@
|
|||||||
render?: Snippet<[item: ComboboxItem]>;
|
render?: Snippet<[item: ComboboxItem]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ComboboxChangeEvent = {
|
|
||||||
value: ComboboxItem;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getLabel = (item: ComboboxItem | undefined): string => item?.label ?? item?.value ?? '';
|
const getLabel = (item: ComboboxItem | undefined): string => item?.label ?? item?.value ?? '';
|
||||||
const getPreview = (item: ComboboxItem | undefined): string => item?.preview ?? getLabel(item);
|
const getPreview = (item: ComboboxItem | undefined): string => item?.preview ?? getLabel(item);
|
||||||
</script>
|
</script>
|
||||||
@@ -45,7 +41,7 @@
|
|||||||
notFoundMessage?: string;
|
notFoundMessage?: string;
|
||||||
class?: ClassValue | null | undefined;
|
class?: ClassValue | null | undefined;
|
||||||
onvalidate?: (e: InputValidatorEvent) => void;
|
onvalidate?: (e: InputValidatorEvent) => void;
|
||||||
onchange?: (e: ComboboxChangeEvent) => void;
|
onchange?: (item: ComboboxItem) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -291,7 +287,7 @@
|
|||||||
value = item;
|
value = item;
|
||||||
open = false;
|
open = false;
|
||||||
searchInput?.focus();
|
searchInput?.focus();
|
||||||
onchange?.({ value: item });
|
onchange?.(item);
|
||||||
}}
|
}}
|
||||||
onkeydown={() => {}}
|
onkeydown={() => {}}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
@@ -398,7 +394,7 @@
|
|||||||
if (e.key === 'Tab' || e.key === 'Enter') {
|
if (e.key === 'Tab' || e.key === 'Enter') {
|
||||||
if (open && highlighted && highlighted.value !== value?.value) {
|
if (open && highlighted && highlighted.value !== value?.value) {
|
||||||
value = highlighted;
|
value = highlighted;
|
||||||
onchange?.({ value: highlighted });
|
onchange?.(highlighted);
|
||||||
}
|
}
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -127,8 +127,8 @@
|
|||||||
bind:value={selectedCountryItem}
|
bind:value={selectedCountryItem}
|
||||||
bind:open={countriesOpen}
|
bind:open={countriesOpen}
|
||||||
{required}
|
{required}
|
||||||
onchange={(e) => {
|
onchange={(item) => {
|
||||||
country = countrycodeMap[e.value.value];
|
country = countrycodeMap[item.value];
|
||||||
}}
|
}}
|
||||||
onvalidate={(e) => {
|
onvalidate={(e) => {
|
||||||
countriesValid = e.detail.valid;
|
countriesValid = e.detail.valid;
|
||||||
|
|||||||
@@ -2,11 +2,7 @@
|
|||||||
export { default as Button } from './Button.svelte';
|
export { default as Button } from './Button.svelte';
|
||||||
export { default as CenterBox } from './CenterBox.svelte';
|
export { default as CenterBox } from './CenterBox.svelte';
|
||||||
export { default as Checkbox } from './Checkbox.svelte';
|
export { default as Checkbox } from './Checkbox.svelte';
|
||||||
export {
|
export { default as Combobox, type ComboboxItem } from './Combobox.svelte';
|
||||||
default as Combobox,
|
|
||||||
type ComboboxItem,
|
|
||||||
type ComboboxChangeEvent
|
|
||||||
} from './Combobox.svelte';
|
|
||||||
export { default as FramelessButton } from './FramelessButton.svelte';
|
export { default as FramelessButton } from './FramelessButton.svelte';
|
||||||
export { default as InjectGoogleMaps } from './InjectGoogleMaps.svelte';
|
export { default as InjectGoogleMaps } from './InjectGoogleMaps.svelte';
|
||||||
export { default as InjectUmami } from './InjectUmami.svelte';
|
export { default as InjectUmami } from './InjectUmami.svelte';
|
||||||
|
|||||||
Reference in New Issue
Block a user