Skip to content

Commit

Permalink
Fixed #14137 - AutoComplete | Refactor onAnimationStart method
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Nov 16, 2023
1 parent 44f2601 commit 31607bf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/app/components/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
*ngIf="virtualScroll"
#scroller
[items]="visibleOptions()"
[tabindex]="-1"
[style]="{ height: scrollHeight }"
[itemSize]="virtualScrollItemSize || _itemSize"
[autoSize]="true"
Expand Down Expand Up @@ -1568,7 +1567,26 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr
onOverlayAnimationStart(event: AnimationEvent) {
if (event.toState === 'visible') {
this.itemsWrapper = DomHandler.findSingle(this.overlayViewChild.overlayViewChild?.nativeElement, this.virtualScroll ? '.p-scroller' : '.p-autocomplete-panel');
this.virtualScroll && this.scroller?.setContentEl(this.itemsViewChild?.nativeElement);

if(this.virtualScroll) {
this.scroller?.setContentEl(this.itemsViewChild?.nativeElement);
this.scroller.viewInit();
}
if(this.visibleOptions() && this.visibleOptions().length) {
if(this.virtualScroll) {
const selectedIndex = this.modelValue() ? this.focusedOptionIndex() : -1;

if (selectedIndex !== -1) {
this.scroller?.scrollToIndex(selectedIndex);
}
} else {
let selectedListItem = DomHandler.findSingle(this.itemsWrapper, '.p-autocomplete-item.p-highlight');

if (selectedListItem) {
selectedListItem.scrollIntoView({ block: 'nearest', inline: 'center' });
}
}
}
}
}

Expand Down

0 comments on commit 31607bf

Please sign in to comment.