mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 09:56:36 +00:00
Autofocus the first element in the auth page (#3177)
This commit is contained in:
parent
af6ade8eb6
commit
f70dafa192
@ -1,4 +1,11 @@
|
|||||||
import { LitElement, html, property, PropertyValues } from "lit-element";
|
import {
|
||||||
|
LitElement,
|
||||||
|
html,
|
||||||
|
property,
|
||||||
|
PropertyValues,
|
||||||
|
CSSResult,
|
||||||
|
css,
|
||||||
|
} from "lit-element";
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import "../components/ha-form";
|
import "../components/ha-form";
|
||||||
import "../components/ha-markdown";
|
import "../components/ha-markdown";
|
||||||
@ -20,19 +27,6 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<style>
|
|
||||||
:host {
|
|
||||||
/* So we can set min-height to avoid jumping during loading */
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.action {
|
|
||||||
margin: 24px 0 8px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.error {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<form>
|
<form>
|
||||||
${this._renderForm()}
|
${this._renderForm()}
|
||||||
</form>
|
</form>
|
||||||
@ -168,7 +162,7 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateStep(data);
|
await this._updateStep(data);
|
||||||
} else {
|
} else {
|
||||||
this._state = "error";
|
this._state = "error";
|
||||||
this._errorMessage = data.message;
|
this._errorMessage = data.message;
|
||||||
@ -199,7 +193,7 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
document.location.assign(url);
|
document.location.assign(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _updateStep(step: ConfigFlowStep) {
|
private async _updateStep(step: ConfigFlowStep) {
|
||||||
let stepData: any = null;
|
let stepData: any = null;
|
||||||
if (
|
if (
|
||||||
this._step &&
|
this._step &&
|
||||||
@ -215,6 +209,15 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
if (stepData != null) {
|
if (stepData != null) {
|
||||||
this._stepData = stepData;
|
this._stepData = stepData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.updateComplete;
|
||||||
|
// 100ms to give all the form elements time to initialize.
|
||||||
|
setTimeout(() => {
|
||||||
|
const form = this.shadowRoot!.querySelector("ha-form");
|
||||||
|
if (form) {
|
||||||
|
(form as any).focus();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeStepDescription(step: ConfigFlowStepForm) {
|
private _computeStepDescription(step: ConfigFlowStepForm) {
|
||||||
@ -282,7 +285,7 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
this._redirect(newStep.result);
|
this._redirect(newStep.result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._updateStep(newStep);
|
await this._updateStep(newStep);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// tslint:disable-next-line: no-console
|
// tslint:disable-next-line: no-console
|
||||||
console.error("Error submitting step", err);
|
console.error("Error submitting step", err);
|
||||||
@ -292,5 +295,21 @@ class HaAuthFlow extends litLocalizeLiteMixin(LitElement) {
|
|||||||
this.style.setProperty("min-height", "");
|
this.style.setProperty("min-height", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult {
|
||||||
|
return css`
|
||||||
|
:host {
|
||||||
|
/* So we can set min-height to avoid jumping during loading */
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.action {
|
||||||
|
margin: 24px 0 8px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
customElements.define("ha-auth-flow", HaAuthFlow);
|
customElements.define("ha-auth-flow", HaAuthFlow);
|
||||||
|
@ -189,6 +189,18 @@ class HaForm extends EventsMixin(PolymerElement) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
const input = this.shadowRoot.querySelector(
|
||||||
|
"ha-form, paper-input, ha-paper-slider, paper-checkbox, paper-dropdown-menu"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!input) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
|
||||||
_isArray(val) {
|
_isArray(val) {
|
||||||
return Array.isArray(val);
|
return Array.isArray(val);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user