bz-select improvements

This commit is contained in:
STEINNI
2025-10-21 08:37:47 +00:00
parent a5733361b9
commit 3b3127b5f2
2 changed files with 17 additions and 6 deletions

View File

@@ -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() })