Fix switch widget not setting the initial state correctly

This commit is contained in:
hadi 2023-10-06 16:06:23 +02:00
parent 2268942532
commit 58d486e6ba

View File

@ -151,14 +151,13 @@ export class Et2Switch extends Et2InputWidget(SlotMixin(SlSwitch))
if(new_value) if(new_value)
{ {
this._labelNode?.classList.add('on'); this._labelNode?.classList.add('on');
this.checked = true;
} }
else else
{ {
this._labelNode?.classList.remove('on'); this._labelNode?.classList.remove('on');
this.checked = false;
} }
} }
this.checked = !!new_value;
return; return;
} }
@ -174,8 +173,9 @@ export class Et2Switch extends Et2InputWidget(SlotMixin(SlSwitch))
labelTemplate() labelTemplate()
{ {
const labelClass = this.checked ? "label on" : "label";
return html` return html`
<span class="label" aria-label="${this.label}"> <span class=${labelClass} aria-label="${this.label}">
<span class="on">${this.toggleOn}</span> <span class="on">${this.toggleOn}</span>
<span class="off">${this.toggleOff}</span> <span class="off">${this.toggleOff}</span>
</span> </span>