Merge pull request #7027 from qburst/master

fix: #7026, Select: Editable Dropdown search not working as expected
pull/7034/head
Tuğçe Küçükoğlu 2024-12-30 14:55:28 +03:00 committed by GitHub
commit 2950c764b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 6 deletions

View File

@ -798,7 +798,10 @@ export default {
hasFocusableElements() { hasFocusableElements() {
return getFocusableElements(this.overlay, ':not([data-p-hidden-focusable="true"])').length > 0; 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)); return this.isValidOption(option) && typeof this.getOptionLabel(option) === 'string' && this.getOptionLabel(option)?.toLocaleLowerCase(this.filterLocale).startsWith(this.searchValue.toLocaleLowerCase(this.filterLocale));
}, },
isValidOption(option) { isValidOption(option) {
@ -846,11 +849,10 @@ export default {
let matched = false; let matched = false;
if (isNotEmpty(this.searchValue)) { if (isNotEmpty(this.searchValue)) {
if (this.focusedOptionIndex !== -1) { optionIndex = this.visibleOptions.findIndex((option) => this.isOptionExactMatched(option));
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; if (optionIndex === -1) {
} else { optionIndex = this.visibleOptions.findIndex((option) => this.isOptionStartsWith(option));
optionIndex = this.visibleOptions.findIndex((option) => this.isOptionMatched(option));
} }
if (optionIndex !== -1) { if (optionIndex !== -1) {