From 292cdc7621f4403ab3ea1e5fbb105ded8c5af163 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Mon, 2 Oct 2023 01:58:10 -0700 Subject: [PATCH] Fix clicking on radio buttons (and improve code) (#18078) --- src/components/ha-formfield.ts | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/ha-formfield.ts b/src/components/ha-formfield.ts index c536f7e820..1c8cc5a019 100644 --- a/src/components/ha-formfield.ts +++ b/src/components/ha-formfield.ts @@ -7,22 +7,25 @@ import { fireEvent } from "../common/dom/fire_event"; @customElement("ha-formfield") export class HaFormfield extends FormfieldBase { protected _labelClick() { - const input = this.input; - if (input) { - input.focus(); - switch (input.tagName) { - case "HA-CHECKBOX": - case "HA-RADIO": - if ((input as any).disabled) { - break; - } - (input as any).checked = !(input as any).checked; - fireEvent(input, "change"); - break; - default: - input.click(); - break; - } + const input = this.input as HTMLInputElement | undefined; + if (!input) return; + + input.focus(); + if (input.disabled) { + return; + } + switch (input.tagName) { + case "HA-CHECKBOX": + input.checked = !input.checked; + fireEvent(input, "change"); + break; + case "HA-RADIO": + input.checked = true; + fireEvent(input, "change"); + break; + default: + input.click(); + break; } }