Fix clicking on radio buttons (and improve code) (#18078)

This commit is contained in:
Kendell R 2023-10-02 01:58:10 -07:00 committed by GitHub
parent c5ba74e0b4
commit 292cdc7621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,16 +7,20 @@ import { fireEvent } from "../common/dom/fire_event";
@customElement("ha-formfield") @customElement("ha-formfield")
export class HaFormfield extends FormfieldBase { export class HaFormfield extends FormfieldBase {
protected _labelClick() { protected _labelClick() {
const input = this.input; const input = this.input as HTMLInputElement | undefined;
if (input) { if (!input) return;
input.focus(); input.focus();
if (input.disabled) {
return;
}
switch (input.tagName) { switch (input.tagName) {
case "HA-CHECKBOX": case "HA-CHECKBOX":
case "HA-RADIO": input.checked = !input.checked;
if ((input as any).disabled) { fireEvent(input, "change");
break; break;
} case "HA-RADIO":
(input as any).checked = !(input as any).checked; input.checked = true;
fireEvent(input, "change"); fireEvent(input, "change");
break; break;
default: default:
@ -24,7 +28,6 @@ export class HaFormfield extends FormfieldBase {
break; break;
} }
} }
}
static override styles = [ static override styles = [
styles, styles,