From cb60631a75f9c317eaf45509e5475d1c69ebe47f Mon Sep 17 00:00:00 2001 From: ANTONA09 Date: Thu, 26 Dec 2024 14:46:56 +0530 Subject: [PATCH] fix: #17220, Select: Editable Dropdown search not working as expected. --- packages/primeng/src/dropdown/dropdown.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/primeng/src/dropdown/dropdown.ts b/packages/primeng/src/dropdown/dropdown.ts index 9495e664348..1f371787560 100755 --- a/packages/primeng/src/dropdown/dropdown.ts +++ b/packages/primeng/src/dropdown/dropdown.ts @@ -1860,18 +1860,10 @@ export class Dropdown extends BaseComponent implements OnInit, AfterViewInit, Af let optionIndex = -1; let matched = false; - if (this.focusedOptionIndex() !== -1) { - optionIndex = this.visibleOptions() - .slice(this.focusedOptionIndex()) - .findIndex((option) => this.isOptionMatched(option)); - optionIndex = - optionIndex === -1 - ? this.visibleOptions() - .slice(0, this.focusedOptionIndex()) - .findIndex((option) => this.isOptionMatched(option)) - : optionIndex + this.focusedOptionIndex(); - } else { - optionIndex = this.visibleOptions().findIndex((option) => this.isOptionMatched(option)); + optionIndex = this.visibleOptions().findIndex((option) => this.isOptionExactMatched(option)); + + if (optionIndex === -1) { + optionIndex = this.visibleOptions().findIndex((option) => this.isOptionStartsWith(option)); } if (optionIndex !== -1) { @@ -1898,10 +1890,14 @@ export class Dropdown extends BaseComponent implements OnInit, AfterViewInit, Af return matched; } - isOptionMatched(option) { + isOptionStartsWith(option) { return this.isValidOption(option) && this.getOptionLabel(option).toString().toLocaleLowerCase(this.filterLocale).startsWith(this.searchValue.toLocaleLowerCase(this.filterLocale)); } + isOptionExactMatched(option) { + return this.isValidOption(option) && this.getOptionLabel(option).toString().toLocaleLowerCase(this.filterLocale) === this.searchValue.toLocaleLowerCase(this.filterLocale); + } + onFilterInputChange(event: Event | any): void { let value: string = (event.target as HTMLInputElement).value; this._filterValue.set(value);