DefinitelyTyped/types/materialize-css/autocomplete.d.ts
Max a355d32369 materialize-css: Add missing declarations and tests (#25492)
* Restructure files and add missing declarations

* Add JQuery declarations

* Restructure tests

* Add carousel tests

* Add more tests and missing JQuery declarations

* Add waves declaration and a test

* Add static init methods and tests

* allow jquery and cash object to be passed to init

* Remove redundant reference

* Clean up

* Clean up

* Clean up and add tests

* Clean up and add tests
2018-05-07 11:00:18 -07:00

89 lines
2.4 KiB
TypeScript

/// <reference path="./common.d.ts" />
declare namespace M {
class Autocomplete extends Component<AutocompleteOptions> {
/**
* Get Instance
*/
static getInstance(elem: Element): Autocomplete;
/**
* Init autocomplete
*/
static init(els: Element, options?: Partial<AutocompleteOptions>): Autocomplete;
/**
* Init autocompletes
*/
static init(els: MElements, options?: Partial<AutocompleteOptions>): Autocomplete[];
/**
* Select a specific autocomplete options.
* @param el Element of the autocomplete option.
*/
selectOption(el: Element): void;
/**
* Update autocomplete options data.
* @param data Autocomplete options data object.
*/
updateData(data: AutocompleteData): void;
/**
* If the autocomplete is open.
*/
isOpen: boolean;
/**
* Number of matching autocomplete options.
*/
count: number;
/**
* Index of the current selected option.
*/
activeIndex: number;
}
interface AutocompleteData {
[key: string]: string | null;
}
interface AutocompleteOptions {
/**
* Data object defining autocomplete options with optional icon strings.
*/
data: AutocompleteData;
/**
* Limit of results the autocomplete shows.
* @default infinity
*/
limit: number;
/**
* Callback for when autocompleted.
*/
onAutocomplete: (this: Autocomplete, text: string) => void;
/**
* Minimum number of characters before autocomplete starts.
* @default 1
*/
minLength: number;
/**
* Sort function that defines the order of the list of autocomplete options.
*/
sortFunction: (a: string, b: string, inputText: string) => number;
}
}
interface JQuery {
// Pick<T,K> to check methods exist.
autocomplete(method: keyof Pick<M.Autocomplete, "destroy">): JQuery;
autocomplete(method: keyof Pick<M.Autocomplete, "selectOption">, el: Element): JQuery;
autocomplete(method: keyof Pick<M.Autocomplete, "updateData">, data: M.AutocompleteData): JQuery;
autocomplete(options?: Partial<M.AutocompleteOptions>): JQuery;
}