Fix invalid style in password manager polyfill and ha-bar (#15603)

This commit is contained in:
Steve Repsher 2023-02-27 04:22:55 -05:00 committed by GitHub
parent 7568ae5964
commit ba3b265b9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 32 deletions

View File

@ -1,6 +1,6 @@
/* eslint-disable lit/prefer-static-styles */ import { css, html, LitElement, nothing } from "lit";
import { html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import type { HaFormSchema } from "../components/ha-form/types"; import type { HaFormSchema } from "../components/ha-form/types";
import { autocompleteLoginFields } from "../data/auth"; import { autocompleteLoginFields } from "../data/auth";
@ -29,35 +29,43 @@ export class HaPasswordManagerPolyfill extends LitElement {
@property({ attribute: false }) public boundingRect?: DOMRect; @property({ attribute: false }) public boundingRect?: DOMRect;
private _styleElement?: HTMLStyleElement;
public connectedCallback() {
super.connectedCallback();
this._styleElement = document.createElement("style");
this._styleElement.textContent = css`
.password-manager-polyfill {
position: absolute;
opacity: 0;
z-index: -1;
}
.password-manager-polyfill input {
width: 100%;
height: 62px;
padding: 0;
border: 0;
}
.password-manager-polyfill input[type="submit"] {
width: 0;
height: 0;
}
`.toString();
document.head.append(this._styleElement);
}
public disconnectedCallback() {
super.disconnectedCallback();
this._styleElement?.remove();
delete this._styleElement;
}
protected createRenderRoot() { protected createRenderRoot() {
// Add under document body so the element isn't placed inside any shadow roots // Add under document body so the element isn't placed inside any shadow roots
return document.body; return document.body;
} }
private get styles() { protected render() {
return `
.password-manager-polyfill {
position: absolute;
top: ${this.boundingRect?.y || 148}px;
left: calc(50% - ${(this.boundingRect?.width || 360) / 2}px);
width: ${this.boundingRect?.width || 360}px;
opacity: 0;
z-index: -1;
}
.password-manager-polyfill input {
width: 100%;
height: 62px;
padding: 0;
border: 0;
}
.password-manager-polyfill input[type="submit"] {
width: 0;
height: 0;
}
`;
}
protected render(): TemplateResult {
if ( if (
this.step && this.step &&
this.step.type === "form" && this.step.type === "form" &&
@ -67,6 +75,11 @@ export class HaPasswordManagerPolyfill extends LitElement {
return html` return html`
<form <form
class="password-manager-polyfill" class="password-manager-polyfill"
style=${styleMap({
top: `${this.boundingRect?.y || 148}px`,
left: `calc(50% - ${(this.boundingRect?.width || 360) / 2}px)`,
width: `${this.boundingRect?.width || 360}px`,
})}
aria-hidden="true" aria-hidden="true"
@submit=${this._handleSubmit} @submit=${this._handleSubmit}
> >
@ -74,16 +87,13 @@ export class HaPasswordManagerPolyfill extends LitElement {
this.render_input(input) this.render_input(input)
)} )}
<input type="submit" /> <input type="submit" />
<style>
${this.styles}
</style>
</form> </form>
`; `;
} }
return html``; return nothing;
} }
private render_input(schema: HaFormSchema): TemplateResult | string { private render_input(schema: HaFormSchema) {
const inputType = schema.name.includes("password") ? "password" : "text"; const inputType = schema.name.includes("password") ? "password" : "text";
if (schema.type !== "string") { if (schema.type !== "string") {
return ""; return "";

View File

@ -44,7 +44,6 @@ export class HaBar extends LitElement {
} }
rect:last-child { rect:last-child {
fill: var(--ha-bar-primary-color, var(--primary-color)); fill: var(--ha-bar-primary-color, var(--primary-color));
rx: var(--ha-bar-border-radius, 4px);
} }
svg { svg {
border-radius: var(--ha-bar-border-radius, 4px); border-radius: var(--ha-bar-border-radius, 4px);