diff --git a/src/cg-dropdown.js b/src/cg-dropdown.js index 605c719..fa781b3 100644 --- a/src/cg-dropdown.js +++ b/src/cg-dropdown.js @@ -8,19 +8,11 @@ export class DropDown { constructor(options = {}) { this.#init(options); - // this.#initAmount(); + this.#initAmount(); this.#render(); // this.#initEvent(); } - #open() { - this.#list = this.#element.querySelector('.list'); - this.#caret = this.#element.querySelector('.caret'); - - this.#list.classList.toggle('open'); - this.#caret.classList.toggle('caret_rotate'); - } - #init(options) { this.#options = options; const elem = document.querySelector(options.selector); @@ -30,29 +22,36 @@ export class DropDown { } this.#element = elem; + + this.#element.addEventListener('click', () => { + this.#selectItem(); + this.#open(); + }); + + this.#list = this.#element.querySelector('.list'); + this.#caret = this.#element.querySelector('.caret'); } #initSelected() { const { styles } = this.#options; - console.log(this.#options.placeholder); - // if (this.#options.selected) { - // this.#createSelected(this.#options.selected); - // } else { - // this.#createSelected('Select...'); - // } + if (this.#options.selected) { + this.#createSelected(this.#options.selected); + } else { + this.#createSelected('Select...'); + } if (!this.#options.selected && this.#options.placeholder) { this.#createSelected(this.#options.placeholder); } - // if ((styles && this.#options.placeholder) || (styles && this.#options.selected)) { - // this.#createSelected(this.#options.placeholder); - // this.#customStyles(styles); - // } else { - // this.#createSelected('Select...'); - // this.#customStyles(styles); - // } + if ((styles && this.#options.placeholder) || (styles && this.#options.selected)) { + this.#createSelected(this.#options.placeholder); + this.#customStyles(styles); + } else { + this.#createSelected('Select...'); + this.#customStyles(styles); + } } #initAmount() { @@ -70,49 +69,53 @@ export class DropDown { this.#element.innerHTML += `