Skip to content

Commit

Permalink
Add autocomplete to onboarding, cloud, and password change (#14040)
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep authored Oct 10, 2022
1 parent 8444fe0 commit a4fcb74
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/ha-selector/ha-selector-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class HaTextSelector extends LitElement {
.disabled=${this.disabled}
@input=${this._handleChange}
autocapitalize="none"
autocomplete="off"
.autocomplete=${this.selector.text.autofill}
spellcheck="false"
.required=${this.required}
autogrow
Expand All @@ -59,6 +59,7 @@ export class HaTextSelector extends LitElement {
html`<div style="width: 24px"></div>`
: this.selector.text?.suffix}
.required=${this.required}
.autocomplete=${this.selector.text.autofill}
></ha-textfield>
${this.selector.text?.type === "password"
? html`<ha-icon-button
Expand Down
9 changes: 9 additions & 0 deletions src/components/ha-textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class HaTextField extends TextFieldBase {
// @ts-ignore
@property({ type: Boolean }) public iconTrailing?: boolean;

@property() public autocomplete?: string;

override updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
if (
Expand All @@ -27,6 +29,13 @@ export class HaTextField extends TextFieldBase {
);
this.reportValidity();
}
if (changedProperties.has("autocomplete")) {
if (this.autocomplete) {
this.formElement.setAttribute("autocomplete", this.autocomplete);
} else {
this.formElement.removeAttribute("autocomplete");
}
}
}

protected override renderIcon(
Expand Down
1 change: 1 addition & 0 deletions src/data/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export interface StringSelector {
| "datetime-local"
| "color";
suffix?: string;
autofill?: string;
};
}

Expand Down
12 changes: 8 additions & 4 deletions src/onboarding/onboarding-create-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ import { onboardUserStep } from "../data/onboarding";
import { PolymerChangedEvent } from "../polymer-types";

const CREATE_USER_SCHEMA: HaFormSchema[] = [
{ name: "name", required: true, selector: { text: {} } },
{ name: "username", required: true, selector: { text: {} } },
{ name: "name", required: true, selector: { text: { autofill: "name" } } },
{
name: "username",
required: true,
selector: { text: { autofill: "username" } },
},
{
name: "password",
required: true,
selector: { text: { type: "password" } },
selector: { text: { type: "password", autofill: "new-password" } },
},
{
name: "password_confirm",
required: true,
selector: { text: { type: "password" } },
selector: { text: { type: "password", autofill: "new-password" } },
},
];

Expand Down
2 changes: 2 additions & 0 deletions src/panels/config/cloud/login/cloud-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class CloudLogin extends LitElement {
)}
id="email"
type="email"
autocomplete="username"
required
.value=${this.email}
@keydown=${this._keyDown}
Expand All @@ -129,6 +130,7 @@ export class CloudLogin extends LitElement {
)}
.value=${this._password || ""}
type="password"
autocomplete="current-password"
required
minlength="8"
@keydown=${this._keyDown}
Expand Down
2 changes: 2 additions & 0 deletions src/panels/config/cloud/register/cloud-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class CloudRegister extends LitElement {
"ui.panel.config.cloud.register.email_address"
)}
type="email"
autocomplete="email"
required
.value=${this.email}
@keydown=${this._keyDown}
Expand All @@ -148,6 +149,7 @@ export class CloudRegister extends LitElement {
label="Password"
.value=${this._password}
type="password"
autocomplete="new-password"
minlength="8"
required
@keydown=${this._keyDown}
Expand Down
2 changes: 2 additions & 0 deletions src/panels/config/users/dialog-admin-change-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SCHEMA = [
selector: {
text: {
type: "password",
autofill: "new-password",
},
},
},
Expand All @@ -29,6 +30,7 @@ const SCHEMA = [
selector: {
text: {
type: "password",
autofill: "new-password",
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/panels/profile/ha-change-password-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class HaChangePasswordCard extends LitElement {
"ui.panel.profile.change_password.current_password"
)}
type="password"
autocomplete="current-password"
.value=${this._currentPassword}
@input=${this._currentPasswordChanged}
required
Expand All @@ -67,6 +68,7 @@ class HaChangePasswordCard extends LitElement {
)}
name="password"
type="password"
autocomplete="new-password"
.value=${this._password}
@change=${this._newPasswordChanged}
required
Expand All @@ -78,6 +80,7 @@ class HaChangePasswordCard extends LitElement {
)}
name="passwordConfirm"
type="password"
autocomplete="new-password"
.value=${this._passwordConfirm}
@input=${this._newPasswordConfirmChanged}
required
Expand Down

0 comments on commit a4fcb74

Please sign in to comment.