diff --git a/types/extended-listbox/extended-listbox-tests.ts b/types/extended-listbox/extended-listbox-tests.ts index dfa51ffebf..4d03ada74e 100644 --- a/types/extended-listbox/extended-listbox-tests.ts +++ b/types/extended-listbox/extended-listbox-tests.ts @@ -12,7 +12,7 @@ options.multiple = true; options.searchBar = false; options.searchBarWatermark = "Search"; options.searchBarButton = { icon: "fa fa-search", visible: true, onClick: function () { alert(); } }; -options.getItems = function (): any[] { +options.getItems = (): (string|ListboxItem)[] => { return ["Test1"]; }; options.onItemsChanged = (event: ListboxEvent): void => { @@ -23,13 +23,13 @@ options.onItemsChanged = (event: ListboxEvent): void => { options.onFilterChanged = (event: ListboxEvent): void => { console.log(event.args); }; -options.onValueChanged = function (event: ListboxEvent): void { +options.onValueChanged = (event: ListboxEvent): void => { console.log(event.args); }; -options.onItemDoubleClicked = function (event: ListboxEvent): void { +options.onItemDoubleClicked = (event: ListboxEvent): void => { console.log(event.args); }; -options.onItemEnterPressed = function (event: ListboxEvent): void { +options.onItemEnterPressed = (event: ListboxEvent): void => { console.log(event.args); }; @@ -39,7 +39,7 @@ instance = $test.listbox(options); /////// NEW API /////// // Add string item -var id = instance.addItem("Test2"); +var id: string = instance.addItem("Test2"); // Add item @@ -54,10 +54,18 @@ item.text = "Test3"; id = instance.addItem(item); +// Add string items +var ids: string[] = instance.addItems(["Test2", "Test1"]); + + // Remove item instance.removeItem(id); +// Remove items +instance.removeItems([id, ids[0]]); + + // Get item var i: ListboxItem = instance.getItem(id); diff --git a/types/extended-listbox/index.d.ts b/types/extended-listbox/index.d.ts index 3f3527b903..b8495b2f94 100644 --- a/types/extended-listbox/index.d.ts +++ b/types/extended-listbox/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for extended-listbox 2.0.x +// Type definitions for extended-listbox 3.0.x // Project: https://github.com/code-chris/extended-listbox // Definitions by: Christian Kotzbauer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -26,7 +26,7 @@ interface ListboxItem { parentGroupId?: string; /** list of childItems */ - childItems?: any[]; + childItems?: ListboxItem[]; } interface ListboxSearchBarButtonOptions { @@ -54,7 +54,7 @@ interface ListBoxOptions { multiple?: boolean; /** function which returns a array of items */ - getItems?: () => any; + getItems?: () => (string|ListboxItem)[]; /** callback for selection changes */ onValueChanged?: (event: ListboxEvent) => void; @@ -90,9 +90,15 @@ interface ExtendedListboxInstance { /** Adds a new item to the list */ addItem(item: string|ListboxItem): string; + /** Adds new items to the list */ + addItems(item: (string|ListboxItem)[]): string[]; + /** Removes a item from the list */ removeItem(identifier: string): void; + /** Removes items from the list */ + removeItems(identifiers: string[]): void; + /** Reverts all changes from the DOM */ destroy(): void;