ngx-type-ahead
Version:
Typeahead multi-select dropdown component for angular
167 lines (166 loc) • 4.76 kB
TypeScript
import { OnDestroy, ElementRef, OnChanges, EventEmitter, AfterViewInit, OnInit, Renderer2, SimpleChanges, TemplateRef } from '@angular/core';
import { Observable } from 'rxjs';
import { ControlValueAccessor } from '@angular/forms';
import { TypeaheadSettings, TypeaheadSuggestions } from './typeahead.interface';
/***
* Usage:
*
* <typeahead formControlName="myControlName" [suggestions]="['abc', 'def',...]"></typeahead>
* <typeahead formControlName="myControlName" [suggestions]="Observable.of(['abc', 'def',...])"></typeahead>
*/
export declare class TypeaheadComponent implements ControlValueAccessor, AfterViewInit, OnDestroy, OnInit, OnChanges {
private elementRef;
private renderer;
/** suggestions list - array of strings, objects or Observable */
suggestions: TypeaheadSuggestions;
/**
* template for items in drop down
* properties exposed are item and index
**/
itemTemplate: TemplateRef<any>;
/** field to use from objects as name */
nameField: string;
/** field to use from objects as id */
idField: string;
/** allow custom values */
custom: boolean;
/** allow multiple values */
multi: boolean;
/** use complex suggestions and results */
complex: boolean;
/** use complex suggestions and results */
placeholder: string;
/** Value of form control */
settings: Partial<TypeaheadSettings>;
/** UI Bindings */
readonly multiBinding: boolean;
readonly disabledBinding: boolean;
/** Output value change */
valueChange: EventEmitter<{}>;
isDisabled: boolean;
isExpanded: boolean;
dropDownClass: string;
matches: string[] | Object[];
allMatches: string[] | Object[];
values: any[];
private allMatchesSubscription;
private matchesSubscription;
private callbackQueue;
/**
* Default values for TypeaheadSettings
* @type TypeaheadSettings
* @private
*/
private _settings;
private _input;
private _inputChangeEvent;
private _value;
private _removeInProgress;
/**
* CTOR
* @param elementRef
* @param renderer
*/
constructor(elementRef: ElementRef, renderer: Renderer2);
focusOutHandler(event: any): void;
/**
* On component initialization
*/
ngOnInit(): void;
ngOnChanges(changes: SimpleChanges): void;
suggestionsInit(suggestion$: Observable<any>): void;
/**
* Init method
*/
ngAfterViewInit(): void;
/**
* Cleanup timeout
*/
ngOnDestroy(): void;
/**
* Value getter
* @returns {string|string[]}
*/
/**
* Value setter
* @param value
*/
value: any;
/**
* Handle input change event
* @param {Event} event
*/
handleInputChange(event: Event): void;
/**
* Update value on input change
* @param event
*/
handleInput(event: Event | KeyboardEvent): void;
/**
* Move through collection on dropdown
* @param event
* @param value
*/
handleButton(event: KeyboardEvent | MouseEvent, value: any): void;
/**
* Set value to list of values or as a single value
* @param value
* @param {boolean} collapseMenu
*/
setValue(value: any, collapseMenu?: boolean): void;
/**
* Remove value from list of values or clear out the value
* @param value
*/
removeValue(value: any): void;
toggleDropdown(value?: boolean): void;
/**
* Write new value
* @param value
*/
writeValue(value: any): void;
/**
* Set disabled state of the component
* @param {boolean} value
*/
setDisabledState(value: boolean): void;
onChange: (_: any) => void;
onTouched: () => void;
registerOnChange(fn: (_: any) => void): void;
registerOnTouched(fn: () => void): void;
/**
* @param {string} searchString
* @returns {(value: any) => boolean}
*/
private filterSuggestion(searchString);
/**
* Check if value has match
* @param {string | Object} value
* @returns {boolean}
*/
private hasMatch(value);
/**
* Get name by parsing id into object
* @param id
* @returns {string}
*/
private extractNameById(id);
/**
* Get complex object from id
* @param id
* @returns {any}
*/
private parseObjectById(id);
/**
* Extract id field from the complex object by name or return value if it's string
* @param {string | Object} value
* @returns {any}
*/
private extractIdentifier(value);
/**
* Extract name from complex object or return value if it's string
* @param {string | Object} value
* @returns {any}
*/
private extractName(value);
}