diff --git a/src/typeahead/typeahead-container.component.ts b/src/typeahead/typeahead-container.component.ts index 5220e44621..6a99e8a31a 100644 --- a/src/typeahead/typeahead-container.component.ts +++ b/src/typeahead/typeahead-container.component.ts @@ -116,6 +116,13 @@ export class TypeaheadContainerComponent implements OnDestroy { set active(active: TypeaheadMatch | undefined) { this._active = active; + + let preview; + if (!(this._active == null || this._active.isHeader())) { + preview = active; + } + this.parent?.typeaheadOnPreview.emit(preview); + this.activeChanged(); } @@ -140,7 +147,7 @@ export class TypeaheadContainerComponent implements OnDestroy { } if (this.typeaheadIsFirstItemActive && this._matches.length > 0) { - this.setActive(this._matches[0]); + this.active = this._matches[0]; if (this._active?.isHeader()) { this.nextActiveMatch(); @@ -220,9 +227,9 @@ export class TypeaheadContainerComponent implements OnDestroy { } const index = this.matches.indexOf(this._active); - this.setActive(this.matches[ + this.active = this.matches[ index - 1 < 0 ? this.matches.length - 1 : index - 1 - ]); + ]; if (this._active.isHeader()) { this.prevActiveMatch(); @@ -235,9 +242,9 @@ export class TypeaheadContainerComponent implements OnDestroy { nextActiveMatch(): void { const index = this._active ? this.matches.indexOf(this._active) : -1; - this.setActive(this.matches[ + this.active = this.matches[ index + 1 > this.matches.length - 1 ? 0 : index + 1 - ]); + ]; if (this._active?.isHeader()) { this.nextActiveMatch(); @@ -250,7 +257,7 @@ export class TypeaheadContainerComponent implements OnDestroy { selectActive(value: TypeaheadMatch): void { this.isFocused = true; - this.setActive(value); + this.active = value; } highlight(match: TypeaheadMatch, query: string[] | string): string { @@ -295,7 +302,7 @@ export class TypeaheadContainerComponent implements OnDestroy { focusLost(): void { this.isFocused = false; if (!this.canSelectItemsOnBlur) { - this.setActive(void 0); + this.active = void 0; } } @@ -370,15 +377,6 @@ export class TypeaheadContainerComponent implements OnDestroy { this.positionServiceSubscription.unsubscribe(); } - protected setActive(value?: TypeaheadMatch): void { - this._active = value; - let preview; - if (!(this._active == null || this._active.isHeader())) { - preview = value; - } - this.parent?.typeaheadOnPreview.emit(preview); - } - private isScrolledIntoView(elem: HTMLElement): boolean { if (!this.ulElement) { return false;