Skip to content

Commit

Permalink
Set initial focus for supervisor dialogs (#11710)
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep authored Feb 21, 2022
1 parent 6cac7ee commit 2281f5b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 5 deletions.
8 changes: 7 additions & 1 deletion hassio/src/components/supervisor-backup-content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mdiFolder, mdiHomeAssistant, mdiPuzzle } from "@mdi/js";
import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { customElement, property, query } from "lit/decorators";
import { atLeastVersion } from "../../../src/common/config/version";
import { formatDate } from "../../../src/common/datetime/format_date";
import { formatDateTime } from "../../../src/common/datetime/format_date_time";
Expand Down Expand Up @@ -92,6 +92,8 @@ export class SupervisorBackupContent extends LitElement {

@property() public confirmBackupPassword = "";

@query("paper-input, ha-radio, ha-checkbox", true) private _focusTarget;

public willUpdate(changedProps) {
super.willUpdate(changedProps);
if (!this.hasUpdated) {
Expand All @@ -109,6 +111,10 @@ export class SupervisorBackupContent extends LitElement {
}
}

public override focus() {
this._focusTarget?.focus();
}

private _localize = (string: string) =>
this.supervisor?.localize(`backup.${string}`) ||
this.localize!(`ui.panel.page-onboarding.restore.${string}`);
Expand Down
1 change: 1 addition & 0 deletions hassio/src/dialogs/backup/dialog-hassio-backup-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class DialogHassioBackupUpload
.path=${mdiClose}
slot="actionItems"
dialogAction="cancel"
dialogInitialFocus
></ha-icon-button>
</ha-header-bar>
</div>
Expand Down
1 change: 1 addition & 0 deletions hassio/src/dialogs/backup/dialog-hassio-backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class HassioBackupDialog
.backup=${this._backup}
.onboarding=${this._dialogParams.onboarding || false}
.localize=${this._dialogParams.localize}
dialogInitialFocus
>
</supervisor-backup-content>`}
${this._error
Expand Down
1 change: 1 addition & 0 deletions hassio/src/dialogs/backup/dialog-hassio-create-backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class HassioCreateBackupDialog extends LitElement {
: html`<supervisor-backup-content
.hass=${this.hass}
.supervisor=${this._dialogParams.supervisor}
dialogInitialFocus
>
</supervisor-backup-content>`}
${this._error
Expand Down
7 changes: 6 additions & 1 deletion hassio/src/dialogs/datadisk/dialog-hassio-datadisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class HassioDatadiskDialog extends LitElement {
"dialog.datadisk_move.select_device"
)}
@selected=${this._select_device}
dialogInitialFocus
>
${this.devices.map(
(device) =>
Expand All @@ -111,7 +112,11 @@ class HassioDatadiskDialog extends LitElement {
"dialog.datadisk_move.no_devices"
)}
<mwc-button slot="secondaryAction" @click=${this.closeDialog}>
<mwc-button
slot="secondaryAction"
@click=${this.closeDialog}
dialogInitialFocus
>
${this.dialogParams.supervisor.localize(
"dialog.datadisk_move.cancel"
)}
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/dialogs/hardware/dialog-hassio-hardware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class HassioHardwareDialog extends LitElement {
></ha-icon-button>
<search-input
.hass=${this.hass}
autofocus
dialogInitialFocus
no-label-float
.filter=${this._filter}
@value-changed=${this._handleSearchChange}
Expand Down
5 changes: 4 additions & 1 deletion hassio/src/dialogs/markdown/dialog-hassio-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class HassioMarkdownDialog extends LitElement {
@closed=${this.closeDialog}
.heading=${createCloseHeading(this.hass, this.title)}
>
<ha-markdown .content=${this.content || ""}></ha-markdown>
<ha-markdown
.content=${this.content || ""}
dialogInitialFocus
></ha-markdown>
</ha-dialog>
`;
}
Expand Down
2 changes: 2 additions & 0 deletions hassio/src/dialogs/network/dialog-hassio-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class DialogHassioNetwork
html`<mwc-tab
.id=${device.interface}
.label=${device.interface}
dialogInitialFocus
>
</mwc-tab>`
)}
Expand Down Expand Up @@ -315,6 +316,7 @@ export class DialogHassioNetwork
value="auto"
name="${version}method"
.checked=${this._interface![version]?.method === "auto"}
dialogInitialFocus
>
</ha-radio>
</ha-formfield>
Expand Down
3 changes: 2 additions & 1 deletion hassio/src/dialogs/registries/dialog-hassio-registries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class HassioRegistriesDialog extends LitElement {
.schema=${SCHEMA}
@value-changed=${this._valueChanged}
.computeLabel=${this._computeLabel}
dialogInitialFocus
></ha-form>
<div class="action">
<mwc-button
Expand Down Expand Up @@ -124,7 +125,7 @@ class HassioRegistriesDialog extends LitElement {
</ha-alert>
`}
<div class="action">
<mwc-button @click=${this._addRegistry}>
<mwc-button @click=${this._addRegistry} dialogInitialFocus>
${this.supervisor.localize(
"dialog.registries.add_new_registry"
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class HassioRepositoriesDialog extends LitElement {
"dialog.repositories.add"
)}
@keydown=${this._handleKeyAdd}
dialogInitialFocus
></paper-input>
<mwc-button @click=${this._addRepository}>
${this._processing
Expand Down

0 comments on commit 2281f5b

Please sign in to comment.