Skip to content

Commit

Permalink
Merge pull request #17221 from qburst/master
Browse files Browse the repository at this point in the history
fix: #17220, Select: Editable Dropdown search not working as expected.
  • Loading branch information
cetincakiroglu authored Dec 26, 2024
2 parents f22711e + cb60631 commit 6d5e7b8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/primeng/src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 6d5e7b8

Please sign in to comment.