diff --git a/src/cg-dropdown.js b/src/cg-dropdown.js index 51d5472..c433af0 100644 --- a/src/cg-dropdown.js +++ b/src/cg-dropdown.js @@ -4,8 +4,6 @@ export class DropDown { #options; #caret; - //ToDo: Added url - constructor(options = {}) { this.#init(options); this.#initAmount(); @@ -49,7 +47,6 @@ export class DropDown { this.#createSelected(this.#options.placeholder); this.#customStyles(styles); } else { - this.#createSelected('Select...'); this.#customStyles(styles); } @@ -106,10 +103,18 @@ export class DropDown { items.map((item) => { let li = document.createElement('li'); - const text = document.createTextNode(item); - li.classList.add('list__item'); - li.appendChild(text); + if (typeof item == 'object') { + const text = document.createTextNode(item.value); + li.classList.add('list__item'); + li.appendChild(text); + } else { + const text = document.createTextNode(item); + + li.classList.add('list__item'); + li.appendChild(text); + } + ul.appendChild(li); }); } @@ -251,4 +256,10 @@ export class DropDown { this.#render(select); } + + getElement(number) { + const { items } = this.#options; + + return items[number]; + } } diff --git a/src/index.html b/src/index.html index 366bebf..2856148 100644 --- a/src/index.html +++ b/src/index.html @@ -13,7 +13,7 @@
- +