Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/panels/config/helpers/dialog-helper-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LitElement,
property,
TemplateResult,
query,
} from "lit-element";
import "../../../components/ha-dialog";
import { HomeAssistant } from "../../../types";
Expand Down Expand Up @@ -44,6 +45,7 @@ export class DialogHelperDetail extends LitElement {
@property() private _platform?: string;
@property() private _error?: string;
@property() private _submitting = false;
@query(".form") private _form?: HTMLDivElement;

public async showDialog(): Promise<void> {
this._platform = undefined;
Expand Down Expand Up @@ -108,11 +110,13 @@ export class DialogHelperDetail extends LitElement {
${Object.keys(HELPERS).map((platform: string) => {
const isLoaded = isComponentLoaded(this.hass, platform);
return html`
<div>
<div class="form">
<paper-icon-item
.disabled=${!isLoaded}
@click=${this._platformPicked}
@keydown=${this._handleEnter}
.platform=${platform}
dialogInitialFocus
>
<ha-icon
slot="item-icon"
Expand Down Expand Up @@ -166,12 +170,28 @@ export class DialogHelperDetail extends LitElement {
}
}

private _handleEnter(ev: KeyboardEvent) {
if (ev.keyCode !== 13) {
return;
}
ev.stopPropagation();
ev.preventDefault();
this._platformPicked(ev);
}

private _platformPicked(ev: Event): void {
this._platform = (ev.currentTarget! as any).platform;
this._focusForm();
}

private async _focusForm(): Promise<void> {
await this.updateComplete;
(this._form?.lastElementChild as HTMLElement).focus();
}

private _goBack() {
this._platform = undefined;
this._item = undefined;
}

static get styles(): CSSResult[] {
Expand Down
9 changes: 9 additions & 0 deletions src/panels/config/helpers/forms/ha-input_boolean-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class HaInputBooleanForm extends LitElement {
}
}

public focus() {
this.updateComplete.then(() =>
(this.shadowRoot?.querySelector(
"[dialogInitialFocus]"
) as HTMLElement)?.focus()
);
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -55,6 +63,7 @@ class HaInputBooleanForm extends LitElement {
"ui.dialogs.helper_settings.required_error_msg"
)}"
.invalid=${nameInvalid}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
9 changes: 9 additions & 0 deletions src/panels/config/helpers/forms/ha-input_datetime-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class HaInputDateTimeForm extends LitElement {
}
}

public focus() {
this.updateComplete.then(() =>
(this.shadowRoot?.querySelector(
"[dialogInitialFocus]"
) as HTMLElement)?.focus()
);
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -63,6 +71,7 @@ class HaInputDateTimeForm extends LitElement {
"ui.dialogs.helper_settings.required_error_msg"
)}"
.invalid=${nameInvalid}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
9 changes: 9 additions & 0 deletions src/panels/config/helpers/forms/ha-input_number-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class HaInputNumberForm extends LitElement {
}
}

public focus() {
this.updateComplete.then(() =>
(this.shadowRoot?.querySelector(
"[dialogInitialFocus]"
) as HTMLElement)?.focus()
);
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -74,6 +82,7 @@ class HaInputNumberForm extends LitElement {
"ui.dialogs.helper_settings.required_error_msg"
)}"
.invalid=${nameInvalid}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
9 changes: 9 additions & 0 deletions src/panels/config/helpers/forms/ha-input_select-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class HaInputSelectForm extends LitElement {
}
}

public focus() {
this.updateComplete.then(() =>
(this.shadowRoot?.querySelector(
"[dialogInitialFocus]"
) as HTMLElement)?.focus()
);
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -63,6 +71,7 @@ class HaInputSelectForm extends LitElement {
"ui.dialogs.helper_settings.required_error_msg"
)}"
.invalid=${nameInvalid}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
9 changes: 9 additions & 0 deletions src/panels/config/helpers/forms/ha-input_text-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class HaInputTextForm extends LitElement {
}
}

public focus() {
this.updateComplete.then(() =>
(this.shadowRoot?.querySelector(
"[dialogInitialFocus]"
) as HTMLElement)?.focus()
);
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -66,6 +74,7 @@ class HaInputTextForm extends LitElement {
"ui.dialogs.helper_settings.required_error_msg"
)}"
.invalid=${nameInvalid}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class DialogLovelaceDashboardDetail extends LitElement {
.errorMessage=${this.hass.localize(
"ui.panel.config.lovelace.dashboards.detail.title_required"
)}
dialogInitialFocus
></paper-input>
<ha-icon-input
.value=${this._icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class DialogLovelaceResourceDetail extends LitElement {
"ui.panel.config.lovelace.resources.detail.url_error_msg"
)}
.invalid=${urlInvalid}
dialogInitialFocus
></paper-input>
<br />
<ha-paper-dropdown-menu
Expand Down