Set initial focus for lovelace dialogs (#11667)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Steve Repsher 2022-02-15 11:42:46 -05:00 committed by GitHub
parent e95065ed08
commit f5feb1d8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 8 deletions

View File

@ -207,6 +207,7 @@ export class DialogLovelaceDashboardDetail extends LitElement {
slot="primaryAction" slot="primaryAction"
@click=${this._updateDashboard} @click=${this._updateDashboard}
.disabled=${urlInvalid || titleInvalid || this._submitting} .disabled=${urlInvalid || titleInvalid || this._submitting}
dialogInitialFocus
> >
${this._params.urlPath ${this._params.urlPath
? this._params.dashboard?.id ? this._params.dashboard?.id

View File

@ -94,6 +94,7 @@ export class HuiCreateDialogCard
.label=${this.hass!.localize( .label=${this.hass!.localize(
"ui.panel.lovelace.editor.cardpicker.by_card" "ui.panel.lovelace.editor.cardpicker.by_card"
)} )}
dialogInitialFocus
></mwc-tab> ></mwc-tab>
<mwc-tab <mwc-tab
.label=${this.hass!.localize( .label=${this.hass!.localize(

View File

@ -53,7 +53,11 @@ export class HuiDialogDeleteCard extends LitElement {
` `
: ""} : ""}
</div> </div>
<mwc-button slot="secondaryAction" @click=${this.closeDialog}> <mwc-button
slot="secondaryAction"
@click=${this.closeDialog}
dialogInitialFocus
>
${this.hass!.localize("ui.common.cancel")} ${this.hass!.localize("ui.common.cancel")}
</mwc-button> </mwc-button>
<mwc-button slot="primaryAction" class="warning" @click=${this._delete}> <mwc-button slot="primaryAction" class="warning" @click=${this._delete}>

View File

@ -207,6 +207,7 @@ export class HuiDialogEditCard
@config-changed=${this._handleConfigChanged} @config-changed=${this._handleConfigChanged}
@GUImode-changed=${this._handleGUIModeChanged} @GUImode-changed=${this._handleGUIModeChanged}
@editor-save=${this._save} @editor-save=${this._save}
dialogInitialFocus
></hui-card-element-editor> ></hui-card-element-editor>
</div> </div>
<div class="element-preview"> <div class="element-preview">
@ -242,7 +243,7 @@ export class HuiDialogEditCard
` `
: ""} : ""}
<div slot="primaryAction" @click=${this._save}> <div slot="primaryAction" @click=${this._save}>
<mwc-button @click=${this._cancel}> <mwc-button @click=${this._cancel} dialogInitialFocus>
${this.hass!.localize("ui.common.cancel")} ${this.hass!.localize("ui.common.cancel")}
</mwc-button> </mwc-button>
${this._cardConfig !== undefined && this._dirty ${this._cardConfig !== undefined && this._dirty

View File

@ -92,7 +92,11 @@ export class HuiDialogSuggestCard extends LitElement {
` `
: ""} : ""}
</div> </div>
<mwc-button slot="secondaryAction" @click=${this.closeDialog}> <mwc-button
slot="secondaryAction"
@click=${this.closeDialog}
dialogInitialFocus
>
${this._params.yaml ${this._params.yaml
? this.hass!.localize("ui.common.close") ? this.hass!.localize("ui.common.close")
: this.hass!.localize("ui.common.cancel")} : this.hass!.localize("ui.common.cancel")}

View File

@ -56,15 +56,20 @@ export class HuiCreateDialogHeaderFooter
> >
<div class="elements"> <div class="elements">
${headerFooterElements.map( ${headerFooterElements.map(
(headerFooter) => (headerFooter, index) =>
html` html`
<ha-card <ha-card
role="button"
tabindex="0"
aria-labeledby=${"card-name-" + index}
outlined outlined
.type=${headerFooter.type} .type=${headerFooter.type}
@click=${this._handleHeaderFooterPicked} @click=${this._handleHeaderFooterPicked}
@keyDown=${this._handleHeaderFooterPicked}
dialogInitialFocus
> >
<ha-svg-icon .path=${headerFooter.icon}></ha-svg-icon> <ha-svg-icon .path=${headerFooter.icon}></ha-svg-icon>
<div> <div .id=${"card-name-" + index} role="none presentation">
${this.hass!.localize( ${this.hass!.localize(
`ui.panel.lovelace.editor.header-footer.types.${headerFooter.type}.name` `ui.panel.lovelace.editor.header-footer.types.${headerFooter.type}.name`
)} )}
@ -83,6 +88,15 @@ export class HuiCreateDialogHeaderFooter
} }
private async _handleHeaderFooterPicked(ev: CustomEvent): Promise<void> { private async _handleHeaderFooterPicked(ev: CustomEvent): Promise<void> {
if (
ev instanceof KeyboardEvent &&
ev.key !== "Enter" &&
ev.key !== " " &&
ev.key !== "Spacebar"
) {
return;
}
const type = (ev.currentTarget as any).type; const type = (ev.currentTarget as any).type;
let config: LovelaceHeaderFooterConfig = { type }; let config: LovelaceHeaderFooterConfig = { type };

View File

@ -93,6 +93,7 @@ export class HuiSaveConfig extends LitElement implements HassDialog {
<ha-switch <ha-switch
.checked=${this._emptyConfig} .checked=${this._emptyConfig}
@change=${this._emptyConfigChanged} @change=${this._emptyConfigChanged}
dialogInitialFocus
></ha-switch ></ha-switch
></ha-formfield> ></ha-formfield>
` `
@ -115,6 +116,7 @@ export class HuiSaveConfig extends LitElement implements HassDialog {
<ha-yaml-editor <ha-yaml-editor
.hass=${this.hass} .hass=${this.hass}
.defaultValue=${this._params!.lovelace.config} .defaultValue=${this._params!.lovelace.config}
dialogInitialFocus
></ha-yaml-editor> ></ha-yaml-editor>
`} `}
</div> </div>

View File

@ -50,6 +50,7 @@ export class HuiDialogEditLovelace extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.config=${this._config} .config=${this._config}
@lovelace-config-changed=${this._ConfigChanged} @lovelace-config-changed=${this._ConfigChanged}
dialogInitialFocus
></hui-lovelace-editor> ></hui-lovelace-editor>
</div> </div>
<mwc-button @click=${this.closeDialog} slot="secondaryAction"> <mwc-button @click=${this.closeDialog} slot="secondaryAction">

View File

@ -79,6 +79,7 @@ export class HuiDialogSelectView extends LitElement {
@closed=${stopPropagation} @closed=${stopPropagation}
fixedMenuPosition fixedMenuPosition
naturalMenuWidth naturalMenuWidth
dialogInitialFocus
> >
<mwc-list-item <mwc-list-item
value="lovelace" value="lovelace"
@ -104,7 +105,7 @@ export class HuiDialogSelectView extends LitElement {
${this._config ${this._config
? this._config.views.length > 1 ? this._config.views.length > 1
? html` ? html`
<mwc-list> <mwc-list dialogInitialFocus>
${this._config.views.map( ${this._config.views.map(
(view, idx) => html` (view, idx) => html`
<mwc-radio-list-item <mwc-radio-list-item
@ -124,7 +125,11 @@ export class HuiDialogSelectView extends LitElement {
` `
: "" : ""
: html`<div>No config found.</div>`} : html`<div>No config found.</div>`}
<mwc-button slot="secondaryAction" @click=${this.closeDialog}> <mwc-button
slot="secondaryAction"
@click=${this.closeDialog}
dialogInitialFocus
>
${this.hass!.localize("ui.common.cancel")} ${this.hass!.localize("ui.common.cancel")}
</mwc-button> </mwc-button>
<mwc-button slot="primaryAction" @click=${this._selectView}> <mwc-button slot="primaryAction" @click=${this._selectView}>

View File

@ -183,7 +183,7 @@ export class HuiDialogEditView extends LitElement {
.selected=${this._curTabIndex} .selected=${this._curTabIndex}
@selected-item-changed=${this._handleTabSelected} @selected-item-changed=${this._handleTabSelected}
> >
<paper-tab id="tab-settings" <paper-tab id="tab-settings" dialogInitialFocus
>${this.hass!.localize( >${this.hass!.localize(
"ui.panel.lovelace.editor.edit_view.tab_settings" "ui.panel.lovelace.editor.edit_view.tab_settings"
)}</paper-tab )}</paper-tab