From a2a191d24022e900a1bd097420297291f13d51bd Mon Sep 17 00:00:00 2001 From: joseph rosenthal Date: Wed, 7 Feb 2024 16:41:08 -0500 Subject: [PATCH 1/2] updated how label is computed when computing the label, use all options verses just visible options this new logic will find the selected option whether or not the user is currently filtering because the filtered (i.e. visible) options, are a subset of all the options --- src/app/components/dropdown/dropdown.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/components/dropdown/dropdown.ts b/src/app/components/dropdown/dropdown.ts index 54c58442874..0271aad63e0 100755 --- a/src/app/components/dropdown/dropdown.ts +++ b/src/app/components/dropdown/dropdown.ts @@ -903,7 +903,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV } visibleOptions = computed(() => { - const options = this.group ? this.flatOptions(this.options) : this.options || []; + const options = this.getAllVisibleAndNonVisibleOptions(); if (this._filterValue()) { const _filterBy = this.filterBy || this.optionLabel; @@ -938,9 +938,12 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV }); label = computed(() => { - const selectedOptionIndex = this.findSelectedOptionIndex(); + const options = this.group ? this.flatOptions(this.options) : this.options || []; + // use getAllVisibleAndNonVisibleOptions verses just visible options + // this will find the selected option whether or not the user is currently filtering because the filtered (i.e. visible) options, are a subset of all the options + const selectedOptionIndex = this.getAllVisibleAndNonVisibleOptions().findIndex((option) => this.isValidSelectedOption(option)); - return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder() || 'p-emptylabel'; + return selectedOptionIndex !== -1 ? this.getOptionLabel(options[selectedOptionIndex]) : this.placeholder() || 'p-emptylabel'; }); filled = computed(() => { @@ -971,6 +974,10 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV }); } + private getAllVisibleAndNonVisibleOptions() { + return this.group ? this.flatOptions(this.options) : this.options || []; + } + ngOnInit() { this.id = this.id || UniqueComponentId(); this.autoUpdateModel(); From 1cdac8c375f0a77bc1baa3001f7a040d0cf9ec64 Mon Sep 17 00:00:00 2001 From: joseph rosenthal Date: Wed, 7 Feb 2024 17:03:18 -0500 Subject: [PATCH 2/2] Update dropdown.ts --- src/app/components/dropdown/dropdown.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/components/dropdown/dropdown.ts b/src/app/components/dropdown/dropdown.ts index 0271aad63e0..5869177f568 100755 --- a/src/app/components/dropdown/dropdown.ts +++ b/src/app/components/dropdown/dropdown.ts @@ -938,10 +938,10 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV }); label = computed(() => { - const options = this.group ? this.flatOptions(this.options) : this.options || []; // use getAllVisibleAndNonVisibleOptions verses just visible options // this will find the selected option whether or not the user is currently filtering because the filtered (i.e. visible) options, are a subset of all the options - const selectedOptionIndex = this.getAllVisibleAndNonVisibleOptions().findIndex((option) => this.isValidSelectedOption(option)); + const options = this.getAllVisibleAndNonVisibleOptions(); + const selectedOptionIndex = options.findIndex((option) => this.isValidSelectedOption(option)); return selectedOptionIndex !== -1 ? this.getOptionLabel(options[selectedOptionIndex]) : this.placeholder() || 'p-emptylabel'; });