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,22 +7,25 @@ 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();
switch (input.tagName) { input.focus();
case "HA-CHECKBOX": if (input.disabled) {
case "HA-RADIO": return;
if ((input as any).disabled) { }
break; switch (input.tagName) {
} case "HA-CHECKBOX":
(input as any).checked = !(input as any).checked; input.checked = !input.checked;
fireEvent(input, "change"); fireEvent(input, "change");
break; break;
default: case "HA-RADIO":
input.click(); input.checked = true;
break; fireEvent(input, "change");
} break;
default:
input.click();
break;
} }
} }