Allow setting value to undefined

This commit is contained in:
Talia 2025-01-27 16:08:37 +01:00
parent f55e420cbc
commit 6c3db0456e

View file

@ -385,10 +385,14 @@ export class BetterSelect extends HTMLElement {
get value() { return this.#value.value } get value() { return this.#value.value }
set value(value) { set value(value) {
for (const option of this.options) { if (value === undefined) {
if (option.value === String(value)) { this.clear()
this.setValue(option.value, option.innerText) } else {
return for (const option of Array.from(this.options)) {
if (option.value === String(value)) {
this.setValue(option.value, option.innerText)
return
}
} }
} }
throw `No option with value ${value}` throw `No option with value ${value}`