packages/components/eui-autocomplete/eui-autocomplete.component.ts
eui-autocomplete component with dropdown suggestions, optional chip display for multiple selections, and comprehensive keyboard navigation.
Provides type-ahead functionality with filtering, grouping, sorting, and async data support.
Implements ControlValueAccessor for Angular forms integration with validation support.
eui-autocomplete supports single or multiple selection modes with chips for visual representation of selected items.
Built on Angular CDK Overlay for positioning and virtual scrolling for performance with large datasets.
eui-autocomplete includes accessibility features with ARIA attributes, live announcer, and keyboard navigation.
<eui-autocomplete [autocompleteData]="fruits" placeholder="Select a fruit"></eui-autocomplete><eui-autocomplete
[autocompleteData]="countries"
[hasChips]="true"
[chipsPosition]="'top'"
(selectionChange)="onSelectionChange($event)">
</eui-autocomplete><eui-autocomplete
[autocompleteData]="cities"
[groupBy]="'metadata.continent'"
[isAsync]="true"
[isLoading]="loading">
</eui-autocomplete><eui-autocomplete
[autocompleteData]="options"
formControlName="selection"
[isForceSelection]="true">
</eui-autocomplete>fruits: EuiAutoCompleteItem[] = [
{ id: 1, label: 'Apple' },
{ id: 2, label: 'Banana' },
{ id: 3, label: 'Orange' }
];
onSelectionChange(items: EuiAutoCompleteItem[]): void {
console.log('Selected:', items);
}id and label properties
OnInit
OnDestroy
ControlValueAccessor
OnChanges
AfterViewInit
DoCheck
| changeDetection | ChangeDetectionStrategy.OnPush |
| encapsulation | ViewEncapsulation.None |
| HostDirectives |
BaseStatesDirective
Inputs : euiSecondary euiSuccess euiInfo euiWarning euiDanger
|
| selector | eui-autocomplete, input[euiAutocomplete] |
| imports |
DragDropModule
NgTemplateOutlet
AsyncPipe
ReactiveFormsModule
OverlayModule
ScrollingModule
A11yModule
EuiAutocompleteOptionComponent
EuiAutocompleteOptionGroupComponent
EUI_INPUT_TEXT
EUI_CHIP_LIST
EUI_CHIP
EUI_ICON
EUI_BUTTON
EuiTruncatePipe
EuiTooltipDirective
|
| templateUrl | ./eui-autocomplete.component.html |
| styleUrl | ./eui-autocomplete.scss |
constructor()
|
| autocompleteDataSelected |
Type : EuiAutoCompleteItem[]
|
Default value : []
|
|
Sets the options that will be selected by default. |
| autocompleteData |
Default value : []
|
|
Datas to be used in the autocomplete. |
| chipsLabelTruncateCount |
Default value : null, { transform: numberAttribute }
|
|
Whether the chips label length is limited by the value of this option. |
| chipsPosition |
Type : "top" | "bottom" | "inside"
|
Default value : 'top'
|
| chipsSortOrder |
Type : "ASC" | "DESC"
|
Default value : 'ASC'
|
|
Sets the sort criteria of the chips. |
| classList |
Type : string
|
Default value : null
|
|
Sets a CSS class to be added on the options panel container. |
| groupBy |
Type : string
|
|
Sets a grouping among the options. |
| hasChips |
Default value : false, { transform: booleanAttribute }
|
|
Whether autocomplete will display the selected values with chips. |
| inputId |
|
Sets the id on the text input. |
| isAddOnBlur |
Default value : false, { transform: booleanAttribute }
|
|
In combination with |
| isAsync |
Default value : false, { transform: booleanAttribute }
|
|
Whether autocomplete will get the data asynchronously. |
| isChipsDragAndDrop |
Default value : false, { transform: booleanAttribute }
|
|
Whether the chips can be drag and dropped. |
| isChipsRemovable |
Default value : true, { transform: booleanAttribute }
|
|
Whether the chip can be removed from the selection. When a chip is removed, its value goes back in the panel. |
| isChipsSorted |
Default value : false, { transform: booleanAttribute }
|
|
Whether this chip is sorted on their label. |
| isFreeValueAllowed |
Default value : true, { transform: booleanAttribute }
|
|
In combination with |
| isGroupSorted |
Default value : true, { transform: booleanAttribute }
|
|
Whether the grops of items are sorted on their label. |
| isItemsSorted |
Default value : false, { transform: booleanAttribute }
|
|
Whether this item in the panel is sorted on their label. |
| isLoading |
Default value : false, { transform: booleanAttribute }
|
|
Whether loading spinner is displayed in text input. |
| isMaxVisibleChipsOpened |
Default value : false, { transform: booleanAttribute }
|
|
In combination with |
| isReadonly |
Default value : false, { transform: booleanAttribute }
|
|
Whether autocomplete is in readonly mode. |
| itemsSortOrder |
Type : "ASC" | "DESC"
|
Default value : 'ASC'
|
|
In combination with |
| matching |
Default value : 'contains'
|
|
Sets the way the options should be retrieved. |
| maxVisibleChipsCount |
Default value : null, { transform: numberAttribute }
|
|
Whether a limited amount, defined by this option, is used to display the chips. |
| panelWidth |
Type : string | number
|
|
Sets the width of the options panel. |
| placeholder |
Type : string
|
Default value : ''
|
|
Sets the placeholder of the text input. |
| toggleLinkLessLabel |
Type : string
|
Default value : null
|
|
In combination with |
| toggleLinkMoreLabel |
Type : string
|
Default value : null
|
|
In combination with |
| visibleOptions |
Default value : 5, { transform: numberAttribute }
|
|
Sets the maximum number of options that will be visible in the autocomplete panel. |
| chipDragRelease |
Type : EuiChipDragDrop
|
|
Event emitted when a chip drag is released. |
| chipDragStart |
Type : EuiChipDragDrop
|
|
Event emitted when a chip drag starts. |
| chipDrop |
Type : EuiChipDragDrop
|
|
Event emitted when a chip is dropped. |
| clear |
|
Event emitted when the text input is cleared. |
| inputBlur |
|
Event emitted when the text input is blurred. |
| inputChange |
Type : string
|
|
Event emitted when the value of the text input changes. |
| inputFocus |
|
Event emitted when the text input gets the focus. |
| itemAdd |
Type : EuiAutoCompleteItem
|
|
Event emitted when an option is selected. |
| itemRemove |
Type : EuiAutoCompleteItem
|
|
Event emitted when an option is removed. |
| panelClose |
|
Event emitted when the panel is closed. |
| panelOpen |
|
Event emitted when the panel is opened. |
| selectionChange |
Type : EuiAutoCompleteItem[]
|
|
Event emitted when an option is selected or when the selection is modified. |
| class |
Type : string
|
|
Computes and returns the CSS classes for the component based on its current state. |
| Public add | ||||||||
add(value: string)
|
||||||||
|
Method called when an option is added through the text input.
Parameters :
Returns :
void
|
| Public closePanel |
closePanel()
|
|
Closes the autocomplete panel.
Returns :
void
|
| Public onBlur |
onBlur()
|
|
Text input blur handler.
Returns :
void
|
| Public onChipDragReleased | ||||||||
onChipDragReleased(e: CdkDragRelease)
|
||||||||
|
Called when a chip is released for reordering or from a source to another.
Parameters :
Returns :
void
|
| Public onChipDragStarted | ||||||||
onChipDragStarted(e: CdkDragStart)
|
||||||||
|
Called when a chip is dragged for reordering or from a source to another.
Parameters :
Returns :
void
|
| Public onChipDropped | ||||||||
onChipDropped(e: CdkDragDrop
|
||||||||
|
Called when a chip is dropped for reordering or from a source to another.
Parameters :
Returns :
void
|
| Public onChipRemove | ||||||
onChipRemove(chip: EuiChip)
|
||||||
|
Called when a chip is removed.
Parameters :
Returns :
void
|
| Public onClear |
onClear()
|
|
Returns :
void
|
| Public onFocus |
onFocus()
|
|
Text input focus handler.
Returns :
void
|
| Public onOptionSelected | ||||||||
onOptionSelected(e: EuiAutoCompleteItem)
|
||||||||
|
Method called when an option is selected.
Parameters :
Returns :
void
|
| Public openPanel |
openPanel()
|
|
Method that creates and opens the panel containing autocomplete options.
Returns :
void
|
| Public optionsTrackByFn | |||||||||
optionsTrackByFn(index: number, item: EuiAutoCompleteItem)
|
|||||||||
|
Parameters :
Returns :
string | number
|
| Public registerOnChange | ||||||
registerOnChange(fn: () => void)
|
||||||
|
Parameters :
Returns :
void
|
| Public registerOnTouched | ||||||
registerOnTouched(fn: () => void)
|
||||||
|
Parameters :
Returns :
void
|
| Public setDisabledState | ||||||
setDisabledState(isDisabled: boolean)
|
||||||
|
Parameters :
Returns :
void
|
| Public toggleTags |
toggleTags()
|
|
Returns :
void
|
| Public writeValue | ||||||
writeValue(value: EuiAutoCompleteItem | EuiAutoCompleteItem[])
|
||||||
|
Parameters :
Returns :
void
|
| Public autocompleteControl |
Type : unknown
|
Default value : new FormControl<string>('')
|
| Public autocompleteOptGroupTemplate |
Type : TemplateRef<literal type>
|
| Public autocompleteOptions |
Type : unknown
|
Default value : signal<EuiAutoCompleteItem[]>(this.autocompleteData())
|
| Public autocompleteOptionTemplate |
Type : TemplateRef<literal type>
|
| Public chips |
Type : EuiChip[]
|
Default value : []
|
| Public distinctOptionGroups |
Type : string[]
|
| Public globalOptionIndex |
Type : number
|
Default value : 0
|
| Public groupedOptions |
Type : unknown
|
Default value : new BehaviorSubject<{ [id: string]: { options: EuiAutoCompleteItem[], ancestorLength: number } }>({})
|
| input |
Type : ElementRef
|
Decorators :
@ViewChild('input', {read: ElementRef})
|
| inputContainerRef |
Type : ElementRef
|
Decorators :
@ViewChild('inputContainerRef')
|
| Public isDisabled |
Type : unknown
|
Default value : false
|
| Public Readonly isVisibleChipsOpened |
Type : Signal<boolean>
|
| Public itemSize |
Type : number
|
Default value : 40
|
| Public selectedOptionIndex |
Type : number
|
Default value : 0
|
| templatePortalContent |
Type : TemplateRef<ElementRef>
|
Decorators :
@ViewChild('templatePortalContent')
|
| templates |
Type : QueryList<EuiTemplateDirective>
|
Decorators :
@ContentChildren(EuiTemplateDirective)
|
| virtualScrolling |
Type : CdkVirtualScrollViewport
|
Decorators :
@ViewChild('virtualScrolling')
|
| cssClasses |
getcssClasses()
|
|
Computes and returns the CSS classes for the component based on its current state.
Returns :
string
|
| isChipsPositionInside |
getisChipsPositionInside()
|
| cdkVirtualScrollViewport |
getcdkVirtualScrollViewport()
|
|
Calculates the height that the virtual scroll need to have.
Returns :
number
|
| isOpen |
getisOpen()
|
|
Returns the opening state of the panel.
Returns :
boolean
|
| hasOptionsResult |
gethasOptionsResult()
|
|
Checks if autocomplete options are available.
Returns :
boolean
|