diff --git a/package.json b/package.json index 9d7e972..09f2584 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "", "scripts": { - "start": "parcel ./src/index.html -p 4500 --open ", + "start": "parcel src/index.html -p 4500 --open ", "build": "parcel build ./src/index.html --public-url /cg-select/", "deploy": "gh-pages -d dist", "predeploy": "npm run build" diff --git a/src/cg-dropdown.js b/src/cg-dropdown.js index 12643ce..b0927ab 100644 --- a/src/cg-dropdown.js +++ b/src/cg-dropdown.js @@ -218,7 +218,7 @@ export class DropDown { const select = this.#element.querySelector('.cg-select'); const nativSelect = this.#element.querySelector('.nativSelect'); - + if (value === true) { this.#element.setAttribute('disabled', true); nativSelect.setAttribute('disabled', true); @@ -758,16 +758,21 @@ export class DropDown { input.oninput = function () { let val = this.value.trim(); + let anyMatch = false; if (val != '') { searchSelect.forEach((elem) => { + let isMatching = new RegExp(val, 'gi').test(elem.textContent); + anyMatch = anyMatch || isMatching; + if (elem.innerText.search(val) == -1) { elem.classList.add('displayHide'); - result.classList.remove('displayHide'); } else { elem.classList.remove('displayHide'); } }); + + result.classList.toggle('displayHide', anyMatch); } else { searchSelect.forEach((elem) => { elem.classList.remove('displayHide');