Skip to content

Commit 06ce722

Browse files
Aru-KuAkshat55
andauthored
fix: resolve cannot read property of undefined when all list items are disabled (#2849)
Co-authored-by: Akshat Patel <[email protected]>
1 parent ea07b2a commit 06ce722

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/dropdown/list/dropdown-list.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
352352
}
353353
}
354354

355-
return elemList[this.index].nativeElement;
355+
return elemList[this.index]?.nativeElement;
356356
}
357357

358358
/**
@@ -490,6 +490,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
490490
updateIndex() {
491491
// initialize index on the first selected item or
492492
// on the next non disabled item if no items are selected
493+
// in case, if all items are disabled, the index value will remain same
493494
const selected = this.getSelected();
494495
if (selected.length) {
495496
this.index = this.displayItems.indexOf(selected[0]);
@@ -513,7 +514,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
513514
event.preventDefault();
514515
if (event.key === "ArrowDown") {
515516
if (this.hasNextElement()) {
516-
this.getNextElement().scrollIntoView({ block: "end" });
517+
this.getNextElement()?.scrollIntoView({ block: "end" });
517518
} else {
518519
this.blurIntent.emit("bottom");
519520
}

0 commit comments

Comments
 (0)