+ {#if titleText && !hideLabel}
{/if}
- {#if invalid}
-
- {/if}
- {#if !invalid && warn}
-
- {/if}
-
+ >
+ {
+ if (key === 'Enter') {
+ open = !open;
+
+ if (
+ highlightedIndex > -1 &&
+ filteredItems[highlightedIndex]?.id !== selectedId
+ ) {
+ open = false;
+ if (filteredItems[highlightedIndex]) {
+ inputValue = filteredItems[highlightedIndex].text;
+ selectedItem = filteredItems[highlightedIndex];
+ selectedId = filteredItems[highlightedIndex].id;
+ }
+ } else {
+ open = false;
+ if (filteredItems[0]) {
+ inputValue = filteredItems[0].text;
+ selectedItem = filteredItems[0];
+ selectedId = filteredItems[0].id;
+ }
+ }
+ highlightedIndex = -1;
+ } else if (key === 'Tab') {
+ open = false;
+ } else if (key === 'ArrowDown') {
+ change(1);
+ } else if (key === 'ArrowUp') {
+ change(-1);
+ } else if (key === 'Escape') {
+ open = false;
+ }
+ }}"
+ on:keyup
+ on:focus
+ on:blur
+ on:blur="{({ relatedTarget }) => {
+ if (!open || !relatedTarget) return;
+ if (
+ relatedTarget &&
+ !['INPUT', 'SELECT', 'TEXTAREA'].includes(relatedTarget.tagName) &&
+ relatedTarget.getAttribute('role') !== 'button' &&
+ relatedTarget.getAttribute('role') !== 'searchbox'
+ ) {
+ ref.focus();
+ }
+ }}"
+ />
+ {#if invalid}
+
+ {/if}
+ {#if !invalid && warn}
+
+ {/if}
+ {#if inputValue}
+
+ {/if}
+
+
{#if open}
-
+
{#each filteredItems as item, i (item.id)}
{itemToString(item)}
+ {#if selectedItem && selectedItem.id === item.id}
+
+ {/if}
{/each}
{/if}
- {#if !inline && !invalid && !warn && helperText}
+ {#if !invalid && helperText && !warn}
{/if}
-
-
diff --git a/types/AutoComplete/AutoComplete.svelte.d.ts b/types/AutoComplete/AutoComplete.svelte.d.ts
index c1a147fc..48e70934 100644
--- a/types/AutoComplete/AutoComplete.svelte.d.ts
+++ b/types/AutoComplete/AutoComplete.svelte.d.ts
@@ -11,13 +11,7 @@ export interface AutoCompleteItem {
}
export interface AutoCompleteProps
- extends svelte.JSX.HTMLAttributes
{
- /**
- * Set the full list of items
- * @default []
- */
- items?: AutoCompleteItem[];
-
+ extends svelte.JSX.HTMLAttributes {
/**
* Override the display of a dropdown item
* @default (item) => item.text || item.id
@@ -37,10 +31,10 @@ export interface AutoCompleteProps
selectedItem?: AutoCompleteItem;
/**
- * Specify the type of dropdown
- * @default "default"
+ * Determine if an item should be filtered given the current combobox value
+ * @default () => []
*/
- type?: "default" | "inline";
+ shouldFilterItem?: (value: string) => AutoCompleteItem[];
/**
* Specify the direction of the dropdown menu
@@ -60,12 +54,6 @@ export interface AutoCompleteProps
*/
open?: boolean;
- /**
- * Set to `true` to use the inline variant
- * @default false
- */
- inline?: boolean;
-
/**
* Set to `true` to enable the light variant
* @default false
@@ -149,6 +137,12 @@ export interface AutoCompleteProps
* @default null
*/
placeholder?: undefined;
+
+ /**
+ * Obtain a reference to the list HTML element
+ * @default null
+ */
+ listRef?: null | HTMLDivElement;
}
export default class AutoComplete extends SvelteComponentTyped<
@@ -158,11 +152,17 @@ export default class AutoComplete extends SvelteComponentTyped<
selectedId: AutoCompleteItemId;
selectedItem: AutoCompleteItem;
}>;
- change: WindowEventMap["change"];
+ keydown: WindowEventMap["keydown"];
+ keyup: WindowEventMap["keyup"];
focus: WindowEventMap["focus"];
blur: WindowEventMap["blur"];
- input: WindowEventMap["input"];
- clear: CustomEvent;
+ clear: WindowEventMap["clear"];
+ scroll: WindowEventMap["scroll"];
},
{ default: { item: AutoCompleteItem; index: number } }
-> {}
+> {
+ /**
+ * Clear the combo box programmatically
+ */
+ clear: (options?: { focus?: boolean }) => void;
+}