diff --git a/src/auth/ha-auth-flow.ts b/src/auth/ha-auth-flow.ts index fea62601a4f1..71e81b9d9156 100644 --- a/src/auth/ha-auth-flow.ts +++ b/src/auth/ha-auth-flow.ts @@ -1,7 +1,7 @@ /* eslint-disable lit/prefer-static-styles */ import "@material/mwc-button"; import { genClientId } from "home-assistant-js-websocket"; -import { CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit"; +import { html, LitElement, nothing, PropertyValues } from "lit"; import { customElement, property, state } from "lit/decorators"; import { LocalizeFunc } from "../common/translations/localize"; import "../components/ha-alert"; @@ -391,10 +391,8 @@ export class HaAuthFlow extends LitElement { } } - static get styles(): CSSResultGroup { - // No shadow dom, styles should be in + ` - : this.schema.description?.suffix} + .suffix=${ + this.isPassword + ? // reserve some space for the icon. + html`
` + : this.schema.description?.suffix + } @input=${this._valueChanged} @change=${this._valueChanged} - /> - ${isPassword - ? html`` - : ""} + >
+ ${this.renderIcon()} + `; } - - protected updated(changedProps: PropertyValues): void { - if (changedProps.has("schema")) { - this.toggleAttribute("own-margin", !!this.schema.required); - } - } - - private _toggleUnmaskedPassword(): void { - this._unmaskedPassword = !this._unmaskedPassword; - } - - private _valueChanged(ev: Event): void { - let value: string | undefined = (ev.target as HTMLInputElement).value; - if (this.data === value) { - return; - } - if (value === "" && !this.schema.required) { - value = undefined; - } - fireEvent(this, "value-changed", { - value, - }); - } - - private get _stringType(): string { - if (this.schema.format) { - if (["email", "url"].includes(this.schema.format)) { - return this.schema.format; - } - if (this.schema.format === "fqdnurl") { - return "url"; - } - } - return "text"; - } - - static get styles(): CSSResultGroup { - // No shadow dom, styles should be in authorize.html.template - return []; - } } declare global { diff --git a/src/auth/ha-auth-form.ts b/src/auth/ha-auth-form.ts index 67ec2d304737..b17f0ca46f79 100644 --- a/src/auth/ha-auth-form.ts +++ b/src/auth/ha-auth-form.ts @@ -1,60 +1,32 @@ /* eslint-disable lit/prefer-static-styles */ -import { CSSResultGroup, html } from "lit"; +import { html } from "lit"; import { customElement } from "lit/decorators"; -import { fireEvent } from "../common/dom/fire_event"; import { HaForm } from "../components/ha-form/ha-form"; -import { HaFormElement, HaFormSchema } from "../components/ha-form/types"; import "./ha-auth-form-string"; @customElement("ha-auth-form") export class HaAuthForm extends HaForm { protected fieldElementName(type: string): string { if (type === "string") { - return "ha-auth-form-string"; + return `ha-auth-form-${type}`; } return super.fieldElementName(type); } protected createRenderRoot() { // attach it as soon as possible to make sure we fetch all events. - this.addEventListener("value-changed", (ev) => { - ev.stopPropagation(); - const schema = (ev.target as HaFormElement).schema as HaFormSchema; - - if (ev.target === this) return; - - const newValue = !schema.name - ? ev.detail.value - : { [schema.name]: ev.detail.value }; - - fireEvent(this, "value-changed", { - value: { ...this.data, ...newValue }, - }); - }); + this.addValueChangedListener(this); return this; } protected render() { return html` ${super.render()} `; } - - static get styles(): CSSResultGroup { - // No shadow dom, styles should be in + ${super.render()} + `; + } + + protected createRenderRoot() { + return this; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-auth-textfield": HaAuthTextField; + } +} diff --git a/src/auth/ha-authorize.ts b/src/auth/ha-authorize.ts index afa9238201c0..8a69a1029fd1 100644 --- a/src/auth/ha-authorize.ts +++ b/src/auth/ha-authorize.ts @@ -1,5 +1,5 @@ /* eslint-disable lit/prefer-static-styles */ -import { CSSResultGroup, html, LitElement, nothing, PropertyValues } from "lit"; +import { html, LitElement, nothing, PropertyValues } from "lit"; import { customElement, property, state } from "lit/decorators"; import punycode from "punycode"; import { applyThemesOnElement } from "../common/dom/apply_themes_on_element"; @@ -248,9 +248,4 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) { private async _handleAuthProviderPick(ev) { this._authProvider = ev.detail; } - - static get styles(): CSSResultGroup { - // No shadow dom, styles should be in