primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 51.8 kB
JavaScript
import * as i0 from '@angular/core';
import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ViewChild, ContentChildren, NgModule } from '@angular/core';
import * as i3 from '@angular/common';
import { CommonModule } from '@angular/common';
import { trigger, transition, style, animate } from '@angular/animations';
import { InputTextModule } from 'primeng/inputtext';
import * as i4 from 'primeng/button';
import { ButtonModule } from 'primeng/button';
import * as i5 from 'primeng/ripple';
import { RippleModule } from 'primeng/ripple';
import * as i1 from 'primeng/api';
import { TranslationKeys, PrimeTemplate, SharedModule } from 'primeng/api';
import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom';
import { UniqueComponentId, ObjectUtils } from 'primeng/utils';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import * as i2 from '@angular/cdk/scrolling';
import { CdkVirtualScrollViewport, ScrollingModule } from '@angular/cdk/scrolling';
const AUTOCOMPLETE_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => AutoComplete),
multi: true
};
class AutoComplete {
constructor(el, renderer, cd, differs, config) {
this.el = el;
this.renderer = renderer;
this.cd = cd;
this.differs = differs;
this.config = config;
this.minLength = 1;
this.delay = 300;
this.type = 'text';
this.autoZIndex = true;
this.baseZIndex = 0;
this.dropdownIcon = "pi pi-chevron-down";
this.unique = true;
this.completeOnFocus = false;
this.completeMethod = new EventEmitter();
this.onSelect = new EventEmitter();
this.onUnselect = new EventEmitter();
this.onFocus = new EventEmitter();
this.onBlur = new EventEmitter();
this.onDropdownClick = new EventEmitter();
this.onClear = new EventEmitter();
this.onKeyUp = new EventEmitter();
this.onShow = new EventEmitter();
this.onHide = new EventEmitter();
this.scrollHeight = '200px';
this.dropdownMode = 'blank';
this.showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)';
this.hideTransitionOptions = '.1s linear';
this.autocomplete = 'off';
this.onModelChange = () => { };
this.onModelTouched = () => { };
this.overlayVisible = false;
this.focus = false;
this.inputFieldValue = null;
this.differ = differs.find([]).create(null);
this.listId = UniqueComponentId() + '_list';
}
get suggestions() {
return this._suggestions;
}
set suggestions(val) {
this._suggestions = val;
this.handleSuggestionsChange();
}
ngAfterViewChecked() {
//Use timeouts as since Angular 4.2, AfterViewChecked is broken and not called after panel is updated
if (this.suggestionsUpdated && this.overlay && this.overlay.offsetParent) {
setTimeout(() => {
if (this.overlay) {
this.alignOverlay();
}
}, 1);
this.suggestionsUpdated = false;
}
if (this.highlightOptionChanged) {
setTimeout(() => {
if (this.overlay && this.itemsWrapper) {
let listItem = DomHandler.findSingle(this.overlay, 'li.p-highlight');
if (listItem) {
DomHandler.scrollInView(this.itemsWrapper, listItem);
}
if (this.virtualScroll && this.viewPort) {
let range = this.viewPort.getRenderedRange();
this.updateVirtualScrollSelectedIndex();
if (range.start > this.virtualScrollSelectedIndex || range.end < this.virtualScrollSelectedIndex) {
this.viewPort.scrollToIndex(this.virtualScrollSelectedIndex);
}
}
}
}, 1);
this.highlightOptionChanged = false;
}
}
handleSuggestionsChange() {
if (this._suggestions != null && this.loading) {
this.highlightOption = null;
if (this._suggestions.length) {
this.noResults = false;
this.show();
this.suggestionsUpdated = true;
if (this.autoHighlight) {
this.highlightOption = this._suggestions[0];
}
}
else {
this.noResults = true;
if (this.showEmptyMessage) {
this.show();
this.suggestionsUpdated = true;
}
else {
this.hide();
}
}
this.loading = false;
}
}
ngAfterContentInit() {
this.templates.forEach((item) => {
switch (item.getType()) {
case 'item':
this.itemTemplate = item.template;
break;
case 'group':
this.groupTemplate = item.template;
break;
case 'selectedItem':
this.selectedItemTemplate = item.template;
break;
case 'header':
this.headerTemplate = item.template;
break;
case 'empty':
this.emptyTemplate = item.template;
break;
case 'footer':
this.footerTemplate = item.template;
break;
default:
this.itemTemplate = item.template;
break;
}
});
}
updateVirtualScrollSelectedIndex() {
if (this.highlightOption && this.suggestions && this.suggestions.length) {
this.virtualScrollSelectedIndex = this.findOptionIndex(this.highlightOption, this.suggestions);
}
}
writeValue(value) {
this.value = value;
this.filled = this.value && this.value != '';
this.updateInputField();
this.cd.markForCheck();
}
getOptionGroupChildren(optionGroup) {
return this.optionGroupChildren ? ObjectUtils.resolveFieldData(optionGroup, this.optionGroupChildren) : optionGroup.items;
}
getOptionGroupLabel(optionGroup) {
return this.optionGroupLabel ? ObjectUtils.resolveFieldData(optionGroup, this.optionGroupLabel) : (optionGroup.label != undefined ? optionGroup.label : optionGroup);
}
registerOnChange(fn) {
this.onModelChange = fn;
}
registerOnTouched(fn) {
this.onModelTouched = fn;
}
setDisabledState(val) {
this.disabled = val;
this.cd.markForCheck();
}
onInput(event) {
// When an input element with a placeholder is clicked, the onInput event is invoked in IE.
if (!this.inputKeyDown && DomHandler.isIE()) {
return;
}
if (this.timeout) {
clearTimeout(this.timeout);
}
let value = event.target.value;
if (!this.multiple && !this.forceSelection) {
this.onModelChange(value);
}
if (value.length === 0 && !this.multiple) {
this.hide();
this.onClear.emit(event);
this.onModelChange(value);
}
if (value.length >= this.minLength) {
this.timeout = setTimeout(() => {
this.search(event, value);
}, this.delay);
}
else {
this.hide();
}
this.updateFilledState();
this.inputKeyDown = false;
}
onInputClick(event) {
if (this.documentClickListener) {
this.inputClick = true;
}
}
search(event, query) {
//allow empty string but not undefined or null
if (query === undefined || query === null) {
return;
}
this.loading = true;
this.completeMethod.emit({
originalEvent: event,
query: query
});
}
selectItem(option, focus = true) {
if (this.forceSelectionUpdateModelTimeout) {
clearTimeout(this.forceSelectionUpdateModelTimeout);
this.forceSelectionUpdateModelTimeout = null;
}
if (this.multiple) {
this.multiInputEL.nativeElement.value = '';
this.value = this.value || [];
if (!this.isSelected(option) || !this.unique) {
this.value = [...this.value, option];
this.onModelChange(this.value);
}
}
else {
this.inputEL.nativeElement.value = this.resolveFieldData(option);
this.value = option;
this.onModelChange(this.value);
}
this.onSelect.emit(option);
this.updateFilledState();
if (focus) {
this.itemClicked = true;
this.focusInput();
}
}
show() {
if (this.multiInputEL || this.inputEL) {
let hasFocus = this.multiple ?
this.multiInputEL.nativeElement.ownerDocument.activeElement == this.multiInputEL.nativeElement :
this.inputEL.nativeElement.ownerDocument.activeElement == this.inputEL.nativeElement;
if (!this.overlayVisible && hasFocus) {
this.overlayVisible = true;
}
}
}
onOverlayAnimationStart(event) {
switch (event.toState) {
case 'visible':
this.overlay = event.element;
this.itemsWrapper = this.virtualScroll ? DomHandler.findSingle(this.overlay, '.cdk-virtual-scroll-viewport') : this.overlay;
this.appendOverlay();
if (this.autoZIndex) {
this.overlay.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex));
}
this.alignOverlay();
this.bindDocumentClickListener();
this.bindDocumentResizeListener();
this.bindScrollListener();
this.onShow.emit(event);
break;
case 'void':
this.onOverlayHide();
break;
}
}
appendOverlay() {
if (this.appendTo) {
if (this.appendTo === 'body')
document.body.appendChild(this.overlay);
else
DomHandler.appendChild(this.overlay, this.appendTo);
if (!this.overlay.style.minWidth) {
this.overlay.style.minWidth = DomHandler.getWidth(this.el.nativeElement.children[0]) + 'px';
}
}
}
resolveFieldData(value) {
let data = this.field ? ObjectUtils.resolveFieldData(value, this.field) : value;
return data !== (null || undefined) ? data : '';
}
restoreOverlayAppend() {
if (this.overlay && this.appendTo) {
this.el.nativeElement.appendChild(this.overlay);
}
}
alignOverlay() {
if (this.appendTo)
DomHandler.absolutePosition(this.overlay, (this.multiple ? this.multiContainerEL.nativeElement : this.inputEL.nativeElement));
else
DomHandler.relativePosition(this.overlay, (this.multiple ? this.multiContainerEL.nativeElement : this.inputEL.nativeElement));
}
hide() {
this.overlayVisible = false;
this.cd.markForCheck();
}
handleDropdownClick(event) {
if (!this.overlayVisible) {
this.focusInput();
let queryValue = this.multiple ? this.multiInputEL.nativeElement.value : this.inputEL.nativeElement.value;
if (this.dropdownMode === 'blank')
this.search(event, '');
else if (this.dropdownMode === 'current')
this.search(event, queryValue);
this.onDropdownClick.emit({
originalEvent: event,
query: queryValue
});
}
else {
this.hide();
}
}
focusInput() {
if (this.multiple)
this.multiInputEL.nativeElement.focus();
else
this.inputEL.nativeElement.focus();
}
get emptyMessageLabel() {
return this.emptyMessage || this.config.getTranslation(TranslationKeys.EMPTY_MESSAGE);
}
removeItem(item) {
let itemIndex = DomHandler.index(item);
let removedValue = this.value[itemIndex];
this.value = this.value.filter((val, i) => i != itemIndex);
this.onModelChange(this.value);
this.updateFilledState();
this.onUnselect.emit(removedValue);
}
onKeydown(event) {
if (this.overlayVisible) {
switch (event.which) {
//down
case 40:
if (this.group) {
let highlightItemIndex = this.findOptionGroupIndex(this.highlightOption, this.suggestions);
if (highlightItemIndex !== -1) {
let nextItemIndex = highlightItemIndex.itemIndex + 1;
if (nextItemIndex < (this.getOptionGroupChildren(this.suggestions[highlightItemIndex.groupIndex]).length)) {
this.highlightOption = this.getOptionGroupChildren(this.suggestions[highlightItemIndex.groupIndex])[nextItemIndex];
this.highlightOptionChanged = true;
}
else if (this.suggestions[highlightItemIndex.groupIndex + 1]) {
this.highlightOption = this.getOptionGroupChildren(this.suggestions[highlightItemIndex.groupIndex + 1])[0];
this.highlightOptionChanged = true;
}
}
else {
this.highlightOption = this.getOptionGroupChildren(this.suggestions[0])[0];
}
}
else {
let highlightItemIndex = this.findOptionIndex(this.highlightOption, this.suggestions);
if (highlightItemIndex != -1) {
var nextItemIndex = highlightItemIndex + 1;
if (nextItemIndex != (this.suggestions.length)) {
this.highlightOption = this.suggestions[nextItemIndex];
this.highlightOptionChanged = true;
}
}
else {
this.highlightOption = this.suggestions[0];
}
}
event.preventDefault();
break;
//up
case 38:
if (this.group) {
let highlightItemIndex = this.findOptionGroupIndex(this.highlightOption, this.suggestions);
if (highlightItemIndex !== -1) {
let prevItemIndex = highlightItemIndex.itemIndex - 1;
if (prevItemIndex >= 0) {
this.highlightOption = this.getOptionGroupChildren(this.suggestions[highlightItemIndex.groupIndex])[prevItemIndex];
this.highlightOptionChanged = true;
}
else if (prevItemIndex < 0) {
let prevGroup = this.suggestions[highlightItemIndex.groupIndex - 1];
if (prevGroup) {
this.highlightOption = this.getOptionGroupChildren(prevGroup)[this.getOptionGroupChildren(prevGroup).length - 1];
this.highlightOptionChanged = true;
}
}
}
}
else {
let highlightItemIndex = this.findOptionIndex(this.highlightOption, this.suggestions);
if (highlightItemIndex > 0) {
let prevItemIndex = highlightItemIndex - 1;
this.highlightOption = this.suggestions[prevItemIndex];
this.highlightOptionChanged = true;
}
}
event.preventDefault();
break;
//enter
case 13:
if (this.highlightOption) {
this.selectItem(this.highlightOption);
this.hide();
}
event.preventDefault();
break;
//escape
case 27:
this.hide();
event.preventDefault();
break;
//tab
case 9:
if (this.highlightOption) {
this.selectItem(this.highlightOption);
}
this.hide();
break;
}
}
else {
if (event.which === 40 && this.suggestions) {
this.search(event, event.target.value);
}
}
if (this.multiple) {
switch (event.which) {
//backspace
case 8:
if (this.value && this.value.length && !this.multiInputEL.nativeElement.value) {
this.value = [...this.value];
const removedValue = this.value.pop();
this.onModelChange(this.value);
this.updateFilledState();
this.onUnselect.emit(removedValue);
}
break;
}
}
this.inputKeyDown = true;
}
onKeyup(event) {
this.onKeyUp.emit(event);
}
onInputFocus(event) {
if (!this.itemClicked && this.completeOnFocus) {
let queryValue = this.multiple ? this.multiInputEL.nativeElement.value : this.inputEL.nativeElement.value;
this.search(event, queryValue);
}
this.focus = true;
this.onFocus.emit(event);
this.itemClicked = false;
}
onInputBlur(event) {
this.focus = false;
this.onModelTouched();
this.onBlur.emit(event);
}
onInputChange(event) {
if (this.forceSelection) {
let valid = false;
let inputValue = event.target.value.trim();
if (this.suggestions) {
for (let suggestion of this.suggestions) {
let itemValue = this.field ? ObjectUtils.resolveFieldData(suggestion, this.field) : suggestion;
if (itemValue && inputValue === itemValue.trim()) {
valid = true;
this.forceSelectionUpdateModelTimeout = setTimeout(() => {
this.selectItem(suggestion, false);
}, 250);
break;
}
}
}
if (!valid) {
if (this.multiple) {
this.multiInputEL.nativeElement.value = '';
}
else {
this.value = null;
this.inputEL.nativeElement.value = '';
}
this.onClear.emit(event);
this.onModelChange(this.value);
this.updateFilledState();
}
}
}
onInputPaste(event) {
this.onKeydown(event);
}
isSelected(val) {
let selected = false;
if (this.value && this.value.length) {
for (let i = 0; i < this.value.length; i++) {
if (ObjectUtils.equals(this.value[i], val, this.dataKey)) {
selected = true;
break;
}
}
}
return selected;
}
findOptionIndex(option, suggestions) {
let index = -1;
if (suggestions) {
for (let i = 0; i < suggestions.length; i++) {
if (ObjectUtils.equals(option, suggestions[i])) {
index = i;
break;
}
}
}
return index;
}
findOptionGroupIndex(val, opts) {
let groupIndex, itemIndex;
if (opts) {
for (let i = 0; i < opts.length; i++) {
groupIndex = i;
itemIndex = this.findOptionIndex(val, this.getOptionGroupChildren(opts[i]));
if (itemIndex !== -1) {
break;
}
}
}
if (itemIndex !== -1) {
return { groupIndex: groupIndex, itemIndex: itemIndex };
}
else {
return -1;
}
}
updateFilledState() {
if (this.multiple)
this.filled = (this.value && this.value.length) || (this.multiInputEL && this.multiInputEL.nativeElement && this.multiInputEL.nativeElement.value != '');
else
this.filled = (this.inputFieldValue && this.inputFieldValue != '') || (this.inputEL && this.inputEL.nativeElement && this.inputEL.nativeElement.value != '');
;
}
updateInputField() {
let formattedValue = this.resolveFieldData(this.value);
this.inputFieldValue = formattedValue;
if (this.inputEL && this.inputEL.nativeElement) {
this.inputEL.nativeElement.value = formattedValue;
}
this.updateFilledState();
}
bindDocumentClickListener() {
if (!this.documentClickListener) {
const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
this.documentClickListener = this.renderer.listen(documentTarget, 'click', (event) => {
if (event.which === 3) {
return;
}
if (!this.inputClick && !this.isDropdownClick(event)) {
this.hide();
}
this.inputClick = false;
this.cd.markForCheck();
});
}
}
isDropdownClick(event) {
if (this.dropdown) {
let target = event.target;
return (target === this.dropdownButton.nativeElement || target.parentNode === this.dropdownButton.nativeElement);
}
else {
return false;
}
}
unbindDocumentClickListener() {
if (this.documentClickListener) {
this.documentClickListener();
this.documentClickListener = null;
}
}
bindDocumentResizeListener() {
this.documentResizeListener = this.onWindowResize.bind(this);
window.addEventListener('resize', this.documentResizeListener);
}
unbindDocumentResizeListener() {
if (this.documentResizeListener) {
window.removeEventListener('resize', this.documentResizeListener);
this.documentResizeListener = null;
}
}
onWindowResize() {
this.hide();
}
bindScrollListener() {
if (!this.scrollHandler) {
this.scrollHandler = new ConnectedOverlayScrollHandler(this.containerEL.nativeElement, () => {
if (this.overlayVisible) {
this.hide();
}
});
}
this.scrollHandler.bindScrollListener();
}
unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
}
onOverlayHide() {
this.unbindDocumentClickListener();
this.unbindDocumentResizeListener();
this.unbindScrollListener();
this.overlay = null;
this.onHide.emit();
}
ngOnDestroy() {
if (this.forceSelectionUpdateModelTimeout) {
clearTimeout(this.forceSelectionUpdateModelTimeout);
this.forceSelectionUpdateModelTimeout = null;
}
if (this.scrollHandler) {
this.scrollHandler.destroy();
this.scrollHandler = null;
}
this.restoreOverlayAppend();
this.onOverlayHide();
}
}
AutoComplete.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: AutoComplete, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.IterableDiffers }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component });
AutoComplete.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: AutoComplete, selector: "p-autoComplete", inputs: { minLength: "minLength", delay: "delay", style: "style", panelStyle: "panelStyle", styleClass: "styleClass", panelStyleClass: "panelStyleClass", inputStyle: "inputStyle", inputId: "inputId", inputStyleClass: "inputStyleClass", placeholder: "placeholder", readonly: "readonly", disabled: "disabled", virtualScroll: "virtualScroll", itemSize: "itemSize", maxlength: "maxlength", name: "name", required: "required", size: "size", appendTo: "appendTo", autoHighlight: "autoHighlight", forceSelection: "forceSelection", type: "type", autoZIndex: "autoZIndex", baseZIndex: "baseZIndex", ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy", dropdownIcon: "dropdownIcon", unique: "unique", group: "group", completeOnFocus: "completeOnFocus", field: "field", scrollHeight: "scrollHeight", dropdown: "dropdown", showEmptyMessage: "showEmptyMessage", dropdownMode: "dropdownMode", multiple: "multiple", tabindex: "tabindex", dataKey: "dataKey", emptyMessage: "emptyMessage", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions", autofocus: "autofocus", autocomplete: "autocomplete", optionGroupChildren: "optionGroupChildren", optionGroupLabel: "optionGroupLabel", suggestions: "suggestions" }, outputs: { completeMethod: "completeMethod", onSelect: "onSelect", onUnselect: "onUnselect", onFocus: "onFocus", onBlur: "onBlur", onDropdownClick: "onDropdownClick", onClear: "onClear", onKeyUp: "onKeyUp", onShow: "onShow", onHide: "onHide" }, host: { properties: { "class.p-inputwrapper-filled": "filled", "class.p-inputwrapper-focus": "(focus && !disabled) ||\u00A0overlayVisible" } }, providers: [AUTOCOMPLETE_VALUE_ACCESSOR], queries: [{ propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "containerEL", first: true, predicate: ["container"], descendants: true }, { propertyName: "inputEL", first: true, predicate: ["in"], descendants: true }, { propertyName: "multiInputEL", first: true, predicate: ["multiIn"], descendants: true }, { propertyName: "multiContainerEL", first: true, predicate: ["multiContainer"], descendants: true }, { propertyName: "dropdownButton", first: true, predicate: ["ddBtn"], descendants: true }, { propertyName: "viewPort", first: true, predicate: CdkVirtualScrollViewport, descendants: true }], ngImport: i0, template: `
<span #container [ngClass]="{'p-autocomplete p-component':true,'p-autocomplete-dd':dropdown,'p-autocomplete-multiple':multiple}" [ngStyle]="style" [class]="styleClass">
<input *ngIf="!multiple" #in [attr.type]="type" [attr.id]="inputId" [ngStyle]="inputStyle" [class]="inputStyleClass" [autocomplete]="autocomplete" [attr.required]="required" [attr.name]="name"
class="p-autocomplete-input p-inputtext p-component" [ngClass]="{'p-autocomplete-dd-input':dropdown,'p-disabled': disabled}" [value]="inputFieldValue" aria-autocomplete="list" [attr.aria-controls]="listId" role="searchbox" [attr.aria-expanded]="overlayVisible" aria-haspopup="true" [attr.aria-activedescendant]="'p-highlighted-option'"
(click)="onInputClick($event)" (input)="onInput($event)" (keydown)="onKeydown($event)" (keyup)="onKeyup($event)" [attr.autofocus]="autofocus" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (change)="onInputChange($event)" (paste)="onInputPaste($event)"
[attr.placeholder]="placeholder" [attr.size]="size" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [readonly]="readonly" [disabled]="disabled" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-required]="required"
><ul *ngIf="multiple" #multiContainer class="p-autocomplete-multiple-container p-component p-inputtext" [ngClass]="{'p-disabled':disabled,'p-focus':focus}" (click)="multiIn.focus()">
<li #token *ngFor="let val of value" class="p-autocomplete-token">
<ng-container *ngTemplateOutlet="selectedItemTemplate; context: {$implicit: val}"></ng-container>
<span *ngIf="!selectedItemTemplate" class="p-autocomplete-token-label">{{resolveFieldData(val)}}</span>
<span class="p-autocomplete-token-icon pi pi-times-circle" (click)="removeItem(token)" *ngIf="!disabled && !readonly"></span>
</li>
<li class="p-autocomplete-input-token">
<input #multiIn [attr.type]="type" [attr.id]="inputId" [disabled]="disabled" [attr.placeholder]="(value&&value.length ? null : placeholder)" [attr.tabindex]="tabindex" [attr.maxlength]="maxlength" (input)="onInput($event)" (click)="onInputClick($event)"
(keydown)="onKeydown($event)" [readonly]="readonly" (keyup)="onKeyup($event)" [attr.autofocus]="autofocus" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (change)="onInputChange($event)" (paste)="onInputPaste($event)" [autocomplete]="autocomplete"
[ngStyle]="inputStyle" [class]="inputStyleClass" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-required]="required"
aria-autocomplete="list" [attr.aria-controls]="listId" role="searchbox" [attr.aria-expanded]="overlayVisible" aria-haspopup="true" [attr.aria-activedescendant]="'p-highlighted-option'">
</li>
</ul>
<i *ngIf="loading" class="p-autocomplete-loader pi pi-spinner pi-spin"></i><button #ddBtn type="button" pButton [icon]="dropdownIcon" class="p-autocomplete-dropdown" [disabled]="disabled" pRipple
(click)="handleDropdownClick($event)" *ngIf="dropdown" [attr.tabindex]="tabindex"></button>
<div #panel *ngIf="overlayVisible" [ngClass]="['p-autocomplete-panel p-component']" [style.max-height]="virtualScroll ? 'auto' : scrollHeight" [ngStyle]="panelStyle" [class]="panelStyleClass"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)">
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<ul role="listbox" [attr.id]="listId" class="p-autocomplete-items" [ngClass]="{'p-autocomplete-virtualscroll': virtualScroll}">
<ng-container *ngIf="group">
<ng-template ngFor let-optgroup [ngForOf]="suggestions">
<li class="p-autocomplete-item-group">
<span *ngIf="!groupTemplate">{{getOptionGroupLabel(optgroup)||'empty'}}</span>
<ng-container *ngTemplateOutlet="groupTemplate; context: {$implicit: optgroup}"></ng-container>
</li>
<ng-container *ngTemplateOutlet="itemslist; context: {$implicit: getOptionGroupChildren(optgroup)}"></ng-container>
</ng-template>
</ng-container>
<ng-container *ngIf="!group">
<ng-container *ngTemplateOutlet="itemslist; context: {$implicit: suggestions}"></ng-container>
</ng-container>
<ng-template #itemslist let-suggestionsToDisplay>
<ng-container *ngIf="!virtualScroll; else virtualScrollList">
<li role="option" *ngFor="let option of suggestionsToDisplay; let idx = index" class="p-autocomplete-item" pRipple [ngClass]="{'p-highlight': (option === highlightOption)}" [id]="highlightOption == option ? 'p-highlighted-option':''" (click)="selectItem(option)">
<span *ngIf="!itemTemplate">{{resolveFieldData(option)}}</span>
<ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: option, index: idx}"></ng-container>
</li>
</ng-container>
<ng-template #virtualScrollList>
<cdk-virtual-scroll-viewport [ngStyle]="{'height': scrollHeight}" [itemSize]="itemSize" *ngIf="virtualScroll && !noResults">
<ng-container *cdkVirtualFor="let option of suggestionsToDisplay; let i = index; let c = count; let f = first; let l = last; let e = even; let o = odd">
<li role="option" class="p-autocomplete-item" pRipple [ngClass]="{'p-highlight': (option === highlightOption)}" [ngStyle]="{'height': itemSize + 'px'}" [id]="highlightOption == option ? 'p-highlighted-option':''" (click)="selectItem(option)">
<span *ngIf="!itemTemplate">{{resolveFieldData(option)}}</span>
<ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: option, index: i}"></ng-container>
</li>
</ng-container>
</cdk-virtual-scroll-viewport>
</ng-template>
<li *ngIf="noResults && showEmptyMessage" class="p-autocomplete-empty-message">
<ng-container *ngIf="!emptyTemplate; else empty">
{{emptyMessageLabel}}
</ng-container>
<ng-container #empty *ngTemplateOutlet="emptyTemplate"></ng-container>
</li>
</ng-template>
</ul>
<ng-container *ngTemplateOutlet="footerTemplate"></ng-container>
</div>
</span>
`, isInline: true, styles: [".p-autocomplete{display:inline-flex;position:relative}.p-autocomplete-loader{position:absolute;top:50%;margin-top:-.5rem}.p-autocomplete-dd .p-autocomplete-input{flex:1 1 auto;width:1%}.p-autocomplete-dd .p-autocomplete-input,.p-autocomplete-dd .p-autocomplete-multiple-container{border-top-right-radius:0;border-bottom-right-radius:0}.p-autocomplete-dd .p-autocomplete-dropdown{border-top-left-radius:0;border-bottom-left-radius:0}.p-autocomplete .p-autocomplete-panel{min-width:100%}.p-autocomplete-panel{position:absolute;overflow:auto}.p-autocomplete-items{margin:0;padding:0;list-style-type:none}.p-autocomplete-item{cursor:pointer;white-space:nowrap;position:relative;overflow:hidden}.p-autocomplete-multiple-container{margin:0;padding:0;list-style-type:none;cursor:text;overflow:hidden;display:flex;align-items:center;flex-wrap:wrap}.p-autocomplete-token{cursor:default;display:inline-flex;align-items:center;flex:0 0 auto}.p-autocomplete-token-icon{cursor:pointer}.p-autocomplete-input-token{flex:1 1 auto;display:inline-flex}.p-autocomplete-input-token input{border:0;outline:0 none;background-color:transparent;margin:0;padding:0;box-shadow:none;border-radius:0;width:100%}.p-fluid .p-autocomplete{display:flex}.p-fluid .p-autocomplete-dd .p-autocomplete-input{width:1%}"], components: [{ type: i2.CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation"], outputs: ["scrolledIndexChange"] }], directives: [{ type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }, { type: i4.ButtonDirective, selector: "[pButton]", inputs: ["iconPos", "loadingIcon", "label", "icon", "loading"] }, { type: i5.Ripple, selector: "[pRipple]" }, { type: i2.CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { type: i2.CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }], animations: [
trigger('overlayAnimation', [
transition(':enter', [
style({ opacity: 0, transform: 'scaleY(0.8)' }),
animate('{{showTransitionParams}}')
]),
transition(':leave', [
animate('{{hideTransitionParams}}', style({ opacity: 0 }))
])
])
], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: AutoComplete, decorators: [{
type: Component,
args: [{
selector: 'p-autoComplete',
template: `
<span #container [ngClass]="{'p-autocomplete p-component':true,'p-autocomplete-dd':dropdown,'p-autocomplete-multiple':multiple}" [ngStyle]="style" [class]="styleClass">
<input *ngIf="!multiple" #in [attr.type]="type" [attr.id]="inputId" [ngStyle]="inputStyle" [class]="inputStyleClass" [autocomplete]="autocomplete" [attr.required]="required" [attr.name]="name"
class="p-autocomplete-input p-inputtext p-component" [ngClass]="{'p-autocomplete-dd-input':dropdown,'p-disabled': disabled}" [value]="inputFieldValue" aria-autocomplete="list" [attr.aria-controls]="listId" role="searchbox" [attr.aria-expanded]="overlayVisible" aria-haspopup="true" [attr.aria-activedescendant]="'p-highlighted-option'"
(click)="onInputClick($event)" (input)="onInput($event)" (keydown)="onKeydown($event)" (keyup)="onKeyup($event)" [attr.autofocus]="autofocus" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (change)="onInputChange($event)" (paste)="onInputPaste($event)"
[attr.placeholder]="placeholder" [attr.size]="size" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [readonly]="readonly" [disabled]="disabled" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-required]="required"
><ul *ngIf="multiple" #multiContainer class="p-autocomplete-multiple-container p-component p-inputtext" [ngClass]="{'p-disabled':disabled,'p-focus':focus}" (click)="multiIn.focus()">
<li #token *ngFor="let val of value" class="p-autocomplete-token">
<ng-container *ngTemplateOutlet="selectedItemTemplate; context: {$implicit: val}"></ng-container>
<span *ngIf="!selectedItemTemplate" class="p-autocomplete-token-label">{{resolveFieldData(val)}}</span>
<span class="p-autocomplete-token-icon pi pi-times-circle" (click)="removeItem(token)" *ngIf="!disabled && !readonly"></span>
</li>
<li class="p-autocomplete-input-token">
<input #multiIn [attr.type]="type" [attr.id]="inputId" [disabled]="disabled" [attr.placeholder]="(value&&value.length ? null : placeholder)" [attr.tabindex]="tabindex" [attr.maxlength]="maxlength" (input)="onInput($event)" (click)="onInputClick($event)"
(keydown)="onKeydown($event)" [readonly]="readonly" (keyup)="onKeyup($event)" [attr.autofocus]="autofocus" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (change)="onInputChange($event)" (paste)="onInputPaste($event)" [autocomplete]="autocomplete"
[ngStyle]="inputStyle" [class]="inputStyleClass" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledBy" [attr.aria-required]="required"
aria-autocomplete="list" [attr.aria-controls]="listId" role="searchbox" [attr.aria-expanded]="overlayVisible" aria-haspopup="true" [attr.aria-activedescendant]="'p-highlighted-option'">
</li>
</ul>
<i *ngIf="loading" class="p-autocomplete-loader pi pi-spinner pi-spin"></i><button #ddBtn type="button" pButton [icon]="dropdownIcon" class="p-autocomplete-dropdown" [disabled]="disabled" pRipple
(click)="handleDropdownClick($event)" *ngIf="dropdown" [attr.tabindex]="tabindex"></button>
<div #panel *ngIf="overlayVisible" [ngClass]="['p-autocomplete-panel p-component']" [style.max-height]="virtualScroll ? 'auto' : scrollHeight" [ngStyle]="panelStyle" [class]="panelStyleClass"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)">
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<ul role="listbox" [attr.id]="listId" class="p-autocomplete-items" [ngClass]="{'p-autocomplete-virtualscroll': virtualScroll}">
<ng-container *ngIf="group">
<ng-template ngFor let-optgroup [ngForOf]="suggestions">
<li class="p-autocomplete-item-group">
<span *ngIf="!groupTemplate">{{getOptionGroupLabel(optgroup)||'empty'}}</span>
<ng-container *ngTemplateOutlet="groupTemplate; context: {$implicit: optgroup}"></ng-container>
</li>
<ng-container *ngTemplateOutlet="itemslist; context: {$implicit: getOptionGroupChildren(optgroup)}"></ng-container>
</ng-template>
</ng-container>
<ng-container *ngIf="!group">
<ng-container *ngTemplateOutlet="itemslist; context: {$implicit: suggestions}"></ng-container>
</ng-container>
<ng-template #itemslist let-suggestionsToDisplay>
<ng-container *ngIf="!virtualScroll; else virtualScrollList">
<li role="option" *ngFor="let option of suggestionsToDisplay; let idx = index" class="p-autocomplete-item" pRipple [ngClass]="{'p-highlight': (option === highlightOption)}" [id]="highlightOption == option ? 'p-highlighted-option':''" (click)="selectItem(option)">
<span *ngIf="!itemTemplate">{{resolveFieldData(option)}}</span>
<ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: option, index: idx}"></ng-container>
</li>
</ng-container>
<ng-template #virtualScrollList>
<cdk-virtual-scroll-viewport [ngStyle]="{'height': scrollHeight}" [itemSize]="itemSize" *ngIf="virtualScroll && !noResults">
<ng-container *cdkVirtualFor="let option of suggestionsToDisplay; let i = index; let c = count; let f = first; let l = last; let e = even; let o = odd">
<li role="option" class="p-autocomplete-item" pRipple [ngClass]="{'p-highlight': (option === highlightOption)}" [ngStyle]="{'height': itemSize + 'px'}" [id]="highlightOption == option ? 'p-highlighted-option':''" (click)="selectItem(option)">
<span *ngIf="!itemTemplate">{{resolveFieldData(option)}}</span>
<ng-container *ngTemplateOutlet="itemTemplate; context: {$implicit: option, index: i}"></ng-container>
</li>
</ng-container>
</cdk-virtual-scroll-viewport>
</ng-template>
<li *ngIf="noResults && showEmptyMessage" class="p-autocomplete-empty-message">
<ng-container *ngIf="!emptyTemplate; else empty">
{{emptyMessageLabel}}
</ng-container>
<ng-container #empty *ngTemplateOutlet="emptyTemplate"></ng-container>
</li>
</ng-template>
</ul>
<ng-container *ngTemplateOutlet="footerTemplate"></ng-container>
</div>
</span>
`,
animations: [
trigger('overlayAnimation', [
transition(':enter', [
style({ opacity: 0, transform: 'scaleY(0.8)' }),
animate('{{showTransitionParams}}')
]),
transition(':leave', [
animate('{{hideTransitionParams}}', style({ opacity: 0 }))
])
])
],
host: {
'[class.p-inputwrapper-filled]': 'filled',
'[class.p-inputwrapper-focus]': '(focus && !disabled) || overlayVisible'
},
providers: [AUTOCOMPLETE_VALUE_ACCESSOR],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styleUrls: ['./autocomplete.css']
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.IterableDiffers }, { type: i1.PrimeNGConfig }]; }, propDecorators: { minLength: [{
type: Input
}], delay: [{
type: Input
}], style: [{
type: Input
}], panelStyle: [{
type: Input
}], styleClass: [{
type: Input
}], panelStyleClass: [{
type: Input
}], inputStyle: [{
type: Input
}], inputId: [{
type: Input
}], inputStyleClass: [{
type: Input
}], placeholder: [{
type: Input
}], readonly: [{
type: Input
}], disabled: [{
type: Input
}], virtualScroll: [{
type: Input
}], itemSize: [{
type: Input
}], maxlength: [{
type: Input
}], name: [{
type: Input
}], required: [{
type: Input
}], size: [{
type: Input
}], appendTo: [{
type: Input
}], autoHighlight: [{
type: Input
}], forceSelection: [{
type: Input
}], type: [{
type: Input
}], autoZIndex: [{
type: Input
}], baseZIndex: [{
type: Input
}], ariaLabel: [{
type: Input
}], ariaLabelledBy: [{
type: Input
}], dropdownIcon: [{
type: Input
}], unique: [{
type: Input
}], group: [{
type: Input
}], completeOnFocus: [{
type: Input
}], completeMethod: [{
type: Output
}], onSelect: [{
type: Output
}], onUnselect: [{
type: Output
}], onFocus: [{
type: Output
}], onBlur: [{
type: Output
}], onDropdownClick: [{
type: Output
}], onClear: [{
type: Output
}], onKeyUp: [{
type: Output
}], onShow: [{
type: Output
}], onHide: [{
type: Output
}], field: [{
type: Input
}], scrollHeight: [{
type: Input
}], dropdown: [{
type: Input
}], showEmptyMessage: [{
type: Input
}], dropdownMode: [{
type: Input
}], multiple: [{
type: Input
}], tabindex: [{
type: Input
}], dataKey: [{
type: Input
}], emptyMessage: [{
type: Input
}], showTransitionOptions: [{
type: Input
}], hideTransitionOptions: [{
type: Input
}], autofocus: [{
type: Input
}], autocomplete: [{
type: Input
}], optionGroupChildren: [{
type: Input
}], optionGroupLabel: [{
type: Input
}], containerEL: [{
type: ViewChild,
args: ['container']
}], inputEL: [{
type: ViewChild,
args: ['in']
}], multiInputEL: [{
type: ViewChild,
args: ['multiIn']
}], multiContainerEL: [{
type: ViewChild,
args: ['multiContainer']
}], dropdownButton: [{
type: ViewChild,
args: ['