Improve global menu search behavior for multiple terms

This commit is contained in:
Lance Edgar 2023-03-31 14:02:09 -05:00
parent 6ab3898f27
commit 18f8577005

View file

@ -757,8 +757,27 @@
if (!this.globalSearchTerm.length) {
return this.globalSearchData
}
let terms = []
for (let term of this.globalSearchTerm.toLowerCase().split(' ')) {
term = term.trim()
if (term) {
terms.push(term)
}
}
if (!terms.length) {
return this.globalSearchData
}
// all terms must match
return this.globalSearchData.filter((option) => {
return option.label.toLowerCase().indexOf(this.globalSearchTerm.toLowerCase()) >= 0
let label = option.label.toLowerCase()
for (let term of terms) {
if (label.indexOf(term) < 0) {
return false
}
}
return true
})
},