Skip to content

Commit

Permalink
Fixed #14142 - Fix scroll on selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Nov 16, 2023
1 parent 31607bf commit de5f463
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
if (this.virtualScroll) {
const selectedIndex = this.modelValue() ? this.focusedOptionIndex() : -1;
if (selectedIndex !== -1) {
this.scroller?.scrollToIndex(0);
this.scroller?.scrollToIndex(selectedIndex);
}
} else {
let selectedListItem = DomHandler.findSingle(this.itemsWrapper, '.p-dropdown-item.p-highlight');
Expand Down Expand Up @@ -1420,6 +1420,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV

scrollInView(index = -1) {
const id = index !== -1 ? `${this.id}_${index}` : this.focusedOptionId;

if (this.itemsViewChild && this.itemsViewChild.nativeElement) {
const element = DomHandler.findSingle(this.itemsViewChild.nativeElement, `li[id="${id}"]`);
if (element) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
if (this.virtualScroll) {
const selectedIndex = ObjectUtils.isNotEmpty(this.modelValue()) ? this.focusedOptionIndex() : -1;
if (selectedIndex !== -1) {
this.scroller?.scrollToIndex(0);
this.scroller?.scrollToIndex(selectedIndex);
}
} else {
let selectedListItem = DomHandler.findSingle(this.itemsWrapper, '.p-multiselect-item.p-highlight');
Expand Down

1 comment on commit de5f463

@vercel
Copy link

@vercel vercel bot commented on de5f463 Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.