From aa3f5c0c5a838575ad5f4b9a7b9154735135238d Mon Sep 17 00:00:00 2001 From: ANTONA09 Date: Mon, 30 Dec 2024 14:44:44 +0530 Subject: [PATCH] fix: #7026, Select: Editable Dropdown search not working as expected --- packages/primevue/src/select/Select.vue | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/primevue/src/select/Select.vue b/packages/primevue/src/select/Select.vue index 8bc9c760b..4dd99e211 100755 --- a/packages/primevue/src/select/Select.vue +++ b/packages/primevue/src/select/Select.vue @@ -798,7 +798,10 @@ export default { hasFocusableElements() { return getFocusableElements(this.overlay, ':not([data-p-hidden-focusable="true"])').length > 0; }, - isOptionMatched(option) { + isOptionExactMatched(option) { + return this.isValidOption(option) && typeof this.getOptionLabel(option) === 'string' && this.getOptionLabel(option)?.toLocaleLowerCase(this.filterLocale) == this.searchValue.toLocaleLowerCase(this.filterLocale); + }, + isOptionStartsWith(option) { return this.isValidOption(option) && typeof this.getOptionLabel(option) === 'string' && this.getOptionLabel(option)?.toLocaleLowerCase(this.filterLocale).startsWith(this.searchValue.toLocaleLowerCase(this.filterLocale)); }, isValidOption(option) { @@ -846,11 +849,10 @@ export default { let matched = false; if (isNotEmpty(this.searchValue)) { - 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) {