Skip to content

Commit

Permalink
Merge pull request #14665 from rosenthalj/betterDropdownFilterFix
Browse files Browse the repository at this point in the history
Fix #14596 - fixes p-dropdown logic for selectedOption and label
  • Loading branch information
cetincakiroglu authored Feb 1, 2024
2 parents 9b75c71 + 841f889 commit ca25af1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,12 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
});

label = computed(() => {
const selectedOptionIndex = this.findSelectedOptionIndex();
return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel';
// because of timining issues with virtual scroll lazy load PrimeNG demo, keep original logic for virtual scroll
if (this.virtualScroll) {
const selectedOptionIndex = this.findSelectedOptionIndex();
return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel';
}
return this.modelValue() ? this.getOptionLabel(this.selectedOption) : this.placeholder || 'p-emptylabel';
});

selectedOption: any;
Expand All @@ -940,8 +944,11 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
const visibleOptions = this.visibleOptions();

if (visibleOptions && ObjectUtils.isNotEmpty(visibleOptions)) {
this.selectedOption = visibleOptions[this.findSelectedOptionIndex()];
this.cd.markForCheck();
const selectedOptionIndex = this.findSelectedOptionIndex();
if (selectedOptionIndex !== -1 || !modelValue || this.editable) {
this.selectedOption = visibleOptions[selectedOptionIndex];
this.cd.markForCheck();
}
}

if (modelValue !== undefined && this.editable) {
Expand Down

0 comments on commit ca25af1

Please sign in to comment.