forked from denis-taran/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocomplete.d.ts
39 lines (39 loc) · 1.63 KB
/
autocomplete.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export declare const enum EventTrigger {
Keyboard = 0,
Focus = 1
}
export interface AutocompleteItem {
label?: string;
group?: string;
}
export interface AutocompleteSettings<T extends AutocompleteItem> {
input: HTMLInputElement;
render?: (item: T, currentValue: string) => HTMLDivElement | undefined;
renderGroup?: (name: string, currentValue: string) => HTMLDivElement | undefined;
className?: string;
minLength?: number;
emptyMsg?: string;
onSelect: (item: T, input: HTMLInputElement) => void;
/**
* Show autocomplete on focus event. Focus event will ignore the `minLength` property and will always call `fetch`.
*/
showOnFocus?: boolean;
fetch: (text: string, update: (items: T[] | false) => void, trigger: EventTrigger) => void;
debounceWaitMs?: number;
/**
* Callback for additional autocomplete customization
* @param {HTMLInputElement} input - input box associated with autocomplete
* @param {ClientRect | DOMRect} inputRect - size of the input box and its position relative to the viewport
* @param {HTMLDivElement} container - container with suggestions
* @param {number} maxHeight - max height that can be used by autocomplete
*/
customize?: (input: HTMLInputElement, inputRect: ClientRect | DOMRect, container: HTMLDivElement, maxHeight: number) => void;
/**
* Prevents automatic form submit when ENTER is pressed
*/
preventSubmit?: boolean;
}
export interface AutocompleteResult {
destroy: () => void;
}
export default function autocomplete<T extends AutocompleteItem>(settings: AutocompleteSettings<T>): AutocompleteResult;