Fix 2fa login validation, add autofocus to login (#22856)
parent
253c8f358b
commit
ced70fd9a1
|
@ -188,6 +188,7 @@ const createWebpackConfig = ({
|
||||||
"lit/directives/cache$": "lit/directives/cache.js",
|
"lit/directives/cache$": "lit/directives/cache.js",
|
||||||
"lit/directives/repeat$": "lit/directives/repeat.js",
|
"lit/directives/repeat$": "lit/directives/repeat.js",
|
||||||
"lit/directives/live$": "lit/directives/live.js",
|
"lit/directives/live$": "lit/directives/live.js",
|
||||||
|
"lit/directives/keyed$": "lit/directives/keyed.js",
|
||||||
"lit/polyfill-support$": "lit/polyfill-support.js",
|
"lit/polyfill-support$": "lit/polyfill-support.js",
|
||||||
"@lit-labs/virtualizer/layouts/grid":
|
"@lit-labs/virtualizer/layouts/grid":
|
||||||
"@lit-labs/virtualizer/layouts/grid.js",
|
"@lit-labs/virtualizer/layouts/grid.js",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import "@material/mwc-button";
|
||||||
import { genClientId } from "home-assistant-js-websocket";
|
import { genClientId } from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
|
import { keyed } from "lit/directives/keyed";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
import type { LocalizeFunc } from "../common/translations/localize";
|
||||||
import "../components/ha-alert";
|
import "../components/ha-alert";
|
||||||
|
@ -224,7 +225,9 @@ export class HaAuthFlow extends LitElement {
|
||||||
: this.localize("ui.panel.page-authorize.just_checking")}
|
: this.localize("ui.panel.page-authorize.just_checking")}
|
||||||
</h1>
|
</h1>
|
||||||
${this._computeStepDescription(step)}
|
${this._computeStepDescription(step)}
|
||||||
<ha-auth-form
|
${keyed(
|
||||||
|
step.step_id,
|
||||||
|
html`<ha-auth-form
|
||||||
.localize=${this.localize}
|
.localize=${this.localize}
|
||||||
.data=${this._stepData!}
|
.data=${this._stepData!}
|
||||||
.schema=${autocompleteLoginFields(step.data_schema)}
|
.schema=${autocompleteLoginFields(step.data_schema)}
|
||||||
|
@ -233,7 +236,8 @@ export class HaAuthFlow extends LitElement {
|
||||||
.computeLabel=${this._computeLabelCallback(step)}
|
.computeLabel=${this._computeLabelCallback(step)}
|
||||||
.computeError=${this._computeErrorCallback(step)}
|
.computeError=${this._computeErrorCallback(step)}
|
||||||
@value-changed=${this._stepDataChanged}
|
@value-changed=${this._stepDataChanged}
|
||||||
></ha-auth-form>
|
></ha-auth-form>`
|
||||||
|
)}
|
||||||
${this.clientId === genClientId() &&
|
${this.clientId === genClientId() &&
|
||||||
!["select_mfa_module", "mfa"].includes(step.step_id)
|
!["select_mfa_module", "mfa"].includes(step.step_id)
|
||||||
? html`
|
? html`
|
||||||
|
|
|
@ -54,6 +54,7 @@ export class HaAuthFormString extends HaFormString {
|
||||||
.autoValidate=${this.schema.required}
|
.autoValidate=${this.schema.required}
|
||||||
.name=${this.schema.name}
|
.name=${this.schema.name}
|
||||||
.autocomplete=${this.schema.autocomplete}
|
.autocomplete=${this.schema.autocomplete}
|
||||||
|
?autofocus=${this.schema.autofocus}
|
||||||
.suffix=${
|
.suffix=${
|
||||||
this.isPassword
|
this.isPassword
|
||||||
? // reserve some space for the icon.
|
? // reserve some space for the icon.
|
||||||
|
|
|
@ -69,6 +69,7 @@ export class HaAuthTextField extends HaTextField {
|
||||||
name=${ifDefined(this.name === "" ? undefined : this.name)}
|
name=${ifDefined(this.name === "" ? undefined : this.name)}
|
||||||
inputmode=${ifDefined(this.inputMode)}
|
inputmode=${ifDefined(this.inputMode)}
|
||||||
autocapitalize=${ifDefined(autocapitalizeOrUndef)}
|
autocapitalize=${ifDefined(autocapitalizeOrUndef)}
|
||||||
|
?autofocus=${this.autofocus}
|
||||||
@input=${this.handleInputChange}
|
@input=${this.handleInputChange}
|
||||||
@focus=${this.onInputFocus}
|
@focus=${this.onInputFocus}
|
||||||
@blur=${this.onInputBlur}
|
@blur=${this.onInputBlur}
|
||||||
|
@ -246,6 +247,14 @@ export class HaAuthTextField extends HaTextField {
|
||||||
this.append(style);
|
this.append(style);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public firstUpdated() {
|
||||||
|
super.firstUpdated();
|
||||||
|
|
||||||
|
if (this.autofocus) {
|
||||||
|
this.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
|
@ -85,6 +85,7 @@ export interface HaFormStringSchema extends HaFormBaseSchema {
|
||||||
type: "string";
|
type: "string";
|
||||||
format?: string;
|
format?: string;
|
||||||
autocomplete?: string;
|
autocomplete?: string;
|
||||||
|
autofocus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HaFormBooleanSchema extends HaFormBaseSchema {
|
export interface HaFormBooleanSchema extends HaFormBaseSchema {
|
||||||
|
|
|
@ -30,11 +30,11 @@ export const autocompleteLoginFields = (schema: HaFormSchema[]) =>
|
||||||
if (field.type !== "string") return field;
|
if (field.type !== "string") return field;
|
||||||
switch (field.name) {
|
switch (field.name) {
|
||||||
case "username":
|
case "username":
|
||||||
return { ...field, autocomplete: "username" };
|
return { ...field, autocomplete: "username", autofocus: true };
|
||||||
case "password":
|
case "password":
|
||||||
return { ...field, autocomplete: "current-password" };
|
return { ...field, autocomplete: "current-password" };
|
||||||
case "code":
|
case "code":
|
||||||
return { ...field, autocomplete: "one-time-code" };
|
return { ...field, autocomplete: "one-time-code", autofocus: true };
|
||||||
default:
|
default:
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue