Add support for pre-selected options

This commit is contained in:
Talia 2024-12-19 15:44:39 +01:00
parent 61facdbfb9
commit 2f2db6edc6

View file

@ -298,6 +298,9 @@ export class BetterSelect extends HTMLElement {
this.list.replaceChildren() this.list.replaceChildren()
for (const option of this.options) { for (const option of this.options) {
this.list.append(f`<li tabindex="0" part="item" data-value="${option.value}">${option.innerText}</li>`) this.list.append(f`<li tabindex="0" part="item" data-value="${option.value}">${option.innerText}</li>`)
if (option.selected) {
this.value = option.value
}
} }
} }
} }