Fixed search method

This commit is contained in:
Макс Овсяников 2022-11-15 17:42:10 +03:00
parent fc67642d10
commit c25d983a02
2 changed files with 8 additions and 3 deletions

View File

@ -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"

View File

@ -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');