mirror of
https://github.com/home-assistant/frontend.git
synced 2025-10-20 17:20:07 +00:00
45 lines
1019 B
TypeScript
45 lines
1019 B
TypeScript
import { Formfield } from "@material/mwc-formfield";
|
|
import { css, CSSResultGroup } from "lit";
|
|
import { customElement } from "lit/decorators";
|
|
|
|
@customElement("ha-formfield")
|
|
// @ts-expect-error
|
|
export class HaFormfield extends Formfield {
|
|
protected _labelClick() {
|
|
const input = this.input;
|
|
if (input) {
|
|
input.focus();
|
|
switch (input.tagName) {
|
|
case "HA-CHECKBOX":
|
|
case "HA-RADIO":
|
|
(input as any).checked = !(input as any).checked;
|
|
break;
|
|
default:
|
|
input.click();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static get styles(): CSSResultGroup {
|
|
return [
|
|
Formfield.styles,
|
|
css`
|
|
:host(:not([alignEnd])) ::slotted(ha-switch) {
|
|
margin-right: 10px;
|
|
}
|
|
:host([dir="rtl"]:not([alignEnd])) ::slotted(ha-switch) {
|
|
margin-left: 10px;
|
|
margin-right: auto;
|
|
}
|
|
`,
|
|
];
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
"ha-formfield": HaFormfield;
|
|
}
|
|
}
|