Skip to content

Commit

Permalink
fixes logic for selectedOption
Browse files Browse the repository at this point in the history
fixes logic for selectedOption
1) fixes logic for selectedOption
2) uses selectedOption for computing label
-- note: issue with virtual scrolling with lazy loading (PrimeNG Demo) as a result keeping original logic for computing label when virtual load (no harm)
  • Loading branch information
rosenthalj committed Jan 30, 2024
1 parent 24fab48 commit 841f889
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 @@ -924,8 +924,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 @@ -938,8 +942,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 841f889

Please sign in to comment.