-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move auth components from shadow DOM to light DOM #18015
Changes from all commits
8f0c458
e8bd549
344c2f6
ef4c5b3
9f0db2a
8449e2c
792de52
4f9df62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable lit/prefer-static-styles */ | ||
import { TemplateResult, html } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
import { HaFormString } from "../components/ha-form/ha-form-string"; | ||
import "../components/ha-icon-button"; | ||
import "./ha-auth-textfield"; | ||
|
||
@customElement("ha-auth-form-string") | ||
export class HaAuthFormString extends HaFormString { | ||
protected createRenderRoot() { | ||
// add parent style to light dom | ||
const style = document.createElement("style"); | ||
style.innerHTML = HaFormString.elementStyles as unknown as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use |
||
this.append(style); | ||
return this; | ||
} | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<style> | ||
ha-auth-form-string { | ||
display: block; | ||
position: relative; | ||
} | ||
ha-auth-form-string[own-margin] { | ||
margin-bottom: 5px; | ||
} | ||
ha-auth-textfield { | ||
display: block !important; | ||
} | ||
</style> | ||
<ha-auth-textfield | ||
.type=${ | ||
!this.isPassword | ||
? this.stringType | ||
: this.unmaskedPassword | ||
? "text" | ||
: "password" | ||
} | ||
.label=${this.label} | ||
.value=${this.data || ""} | ||
.helper=${this.helper} | ||
helperPersistent | ||
.disabled=${this.disabled} | ||
.required=${this.schema.required} | ||
.autoValidate=${this.schema.required} | ||
.name=${this.schema.name} | ||
.autocomplete=${this.schema.autocomplete} | ||
.suffix=${ | ||
this.isPassword | ||
? // reserve some space for the icon. | ||
html`<div style="width: 24px"></div>` | ||
: this.schema.description?.suffix | ||
} | ||
.validationMessage=${this.schema.required ? "Required" : undefined} | ||
@input=${this._valueChanged} | ||
@change=${this._valueChanged} | ||
></ha-auth-textfield> | ||
${this.renderIcon()} | ||
</ha-auth-textfield> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-auth-form-string": HaAuthFormString; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable lit/prefer-static-styles */ | ||
import { customElement } from "lit/decorators"; | ||
import { HaForm } from "../components/ha-form/ha-form"; | ||
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-${type}`; | ||
} | ||
return super.fieldElementName(type); | ||
} | ||
|
||
protected createRenderRoot() { | ||
// add parent style to light dom | ||
const style = document.createElement("style"); | ||
style.innerHTML = HaForm.elementStyles as unknown as string; | ||
this.append(style); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most browsers don't care I think, but strictly speaking, it should be attached to |
||
// attach it as soon as possible to make sure we fetch all events. | ||
this.addValueChangedListener(this); | ||
return this; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-auth-form": HaAuthForm; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this in
static get styles
, that should also work when using light dom right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static styles doesn't work with light dom. That's the reason I use this hacky thing 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought Lit would do that for use, but ok 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that's something that's done in the default
createRenderRoot
implementation.