bz-select improvements
This commit is contained in:
12
buildoz.js
12
buildoz.js
@@ -55,9 +55,12 @@ class BZselect extends Buildoz {
|
||||
connectedCallback() {
|
||||
super.connectedCallback()
|
||||
this.button = document.createElement('button')
|
||||
this.button.textContent = this.getBZAttribute('label')
|
||||
this.button.textContent = this.getBZAttribute('label')
|
||||
this.prepend(this.button)
|
||||
this.button.addEventListener('click', this.toggle.bind(this))
|
||||
if(!this.optionscontainer) this.optionscontainer = document.createElement('div')
|
||||
this.optionscontainer.classList.add('options-container')
|
||||
this.append(this.optionscontainer)
|
||||
this.options = this.querySelectorAll('option')
|
||||
if(this.#fillFromMarkup){ //can only do it once and only if fillOptions was not already called !!
|
||||
for(const opt of this.options){
|
||||
@@ -112,18 +115,19 @@ class BZselect extends Buildoz {
|
||||
}
|
||||
|
||||
addOption(value, markup){
|
||||
// Caution: you can count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||
// Caution: you cannot count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||
const opt = document.createElement('option')
|
||||
opt.setAttribute('value', value)
|
||||
opt.innerHTML = markup
|
||||
opt.addEventListener('click',this.onClick.bind(this))
|
||||
this.append(opt)
|
||||
if(!this.optionscontainer) this.optionscontainer = document.createElement('div')
|
||||
this.optionscontainer.append(opt)
|
||||
this.options = this.querySelectorAll('option')
|
||||
this.#fillFromMarkup = false
|
||||
}
|
||||
|
||||
fillOptions(opts, erase = true){
|
||||
// Caution: you can count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||
// Caution: you cannot count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||
if(erase){
|
||||
this.options = this.querySelectorAll('option')
|
||||
this.options.forEach(node => { node.remove() })
|
||||
|
||||
Reference in New Issue
Block a user