Update cg-dropdown.js

This commit is contained in:
MaxOvs19 2022-11-15 17:41:08 +03:00 committed by GitHub
parent 734b2b9d56
commit 3160b3d14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -757,16 +757,21 @@ export class DropDown {
input.oninput = function () { input.oninput = function () {
let val = this.value.trim(); let val = this.value.trim();
let anyMatch = false;
if (val != '') { if (val != '') {
searchSelect.forEach((elem) => { searchSelect.forEach((elem) => {
let isMatching = new RegExp(val, 'gi').test(elem.textContent);
anyMatch = anyMatch || isMatching;
if (elem.innerText.search(val) == -1) { if (elem.innerText.search(val) == -1) {
elem.classList.add('displayHide'); elem.classList.add('displayHide');
result.classList.remove('displayHide');
} else { } else {
elem.classList.remove('displayHide'); elem.classList.remove('displayHide');
} }
}); });
result.classList.toggle('displayHide', anyMatch);
} else { } else {
searchSelect.forEach((elem) => { searchSelect.forEach((elem) => {
elem.classList.remove('displayHide'); elem.classList.remove('displayHide');