app/components/satis/dropdown/component_controller.js in satis-2.1.6 vs app/components/satis/dropdown/component_controller.js in satis-2.1.8

- old
+ new

@@ -613,9 +613,35 @@ if (this.filteredSearchQuery.length >= this.minSearchQueryLength && this.nrOfItems === 1 && !this.freeTextValue) { const dataDiv = this.itemTargets[0].closest('[data-satis-dropdown-target="item"]') this.selectItem(dataDiv) this.setSelectedItem(dataDiv.getAttribute("data-satis-dropdown-item-value")) this.searchQueryValue = "" + } else if(this.searchQueryValue?.length > 0) { + // hide all items that don't match the search query + const searchValue = this.searchQueryValue + let matches = [] + this.itemTargets.forEach((item) => { + const text = item.getAttribute("data-satis-dropdown-item-text") + const matched = this.needsExactMatchValue + ? searchValue.localeCompare(text, undefined, { sensitivity: "base" }) === 0 + : new RegExp(searchValue, "i").test(text) + + const isHidden = item.classList.contains("hidden") + if (!isHidden) { + if (matched) { + matches.push(item) + } else { + item.classList.toggle("hidden", true) + } + } + }) + + // don't show results + if (matches.length > 0) { + this.showResultsList(event) + } else { + if (!this.showSelectedItem()) this.hideResultsList(event) + } } if (itemCount > 0) { this.currentPage += 1 }