mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Do not close aliases dialog on enter (#14952)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
e3ac2c149d
commit
e7354ed5a2
@ -3,10 +3,12 @@ import { styles } from "@material/mwc-dialog/mwc-dialog.css";
|
|||||||
import { mdiClose } from "@mdi/js";
|
import { mdiClose } from "@mdi/js";
|
||||||
import { css, html, TemplateResult } from "lit";
|
import { css, html, TemplateResult } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import { FOCUS_TARGET } from "../dialogs/make-dialog-manager";
|
import { FOCUS_TARGET } from "../dialogs/make-dialog-manager";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
|
|
||||||
|
const SUPPRESS_DEFAULT_PRESS_SELECTOR = ["button"];
|
||||||
|
|
||||||
export const createCloseHeading = (
|
export const createCloseHeading = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
title: string | TemplateResult
|
title: string | TemplateResult
|
||||||
@ -32,6 +34,14 @@ export class HaDialog extends DialogBase {
|
|||||||
return html`<slot name="heading"> ${super.renderHeading()} </slot>`;
|
return html`<slot name="heading"> ${super.renderHeading()} </slot>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(): void {
|
||||||
|
super.firstUpdated();
|
||||||
|
this.suppressDefaultPressSelector = [
|
||||||
|
this.suppressDefaultPressSelector,
|
||||||
|
SUPPRESS_DEFAULT_PRESS_SELECTOR,
|
||||||
|
].join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
static override styles = [
|
static override styles = [
|
||||||
styles,
|
styles,
|
||||||
css`
|
css`
|
||||||
|
@ -72,16 +72,21 @@ class DialogEntityAliases extends LitElement {
|
|||||||
dialogInitialFocus=${index}
|
dialogInitialFocus=${index}
|
||||||
.index=${index}
|
.index=${index}
|
||||||
class="flex-auto"
|
class="flex-auto"
|
||||||
label="Alias"
|
.label=${this.hass!.localize(
|
||||||
|
"ui.dialogs.entity_registry.editor.aliases.input_label",
|
||||||
|
{ number: index + 1 }
|
||||||
|
)}
|
||||||
.value=${alias}
|
.value=${alias}
|
||||||
?data-last=${index === this._aliases.length - 1}
|
?data-last=${index === this._aliases.length - 1}
|
||||||
@change=${this._editAlias}
|
@input=${this._editAlias}
|
||||||
|
@keydown=${this._keyDownAlias}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.index=${index}
|
.index=${index}
|
||||||
slot="navigationIcon"
|
slot="navigationIcon"
|
||||||
label=${this.hass!.localize(
|
label=${this.hass!.localize(
|
||||||
"ui.dialogs.entity_registry.editor.aliases.remove_alias"
|
"ui.dialogs.entity_registry.editor.aliases.remove_alias",
|
||||||
|
{ number: index + 1 }
|
||||||
)}
|
)}
|
||||||
@click=${this._removeAlias}
|
@click=${this._removeAlias}
|
||||||
.path=${mdiDeleteOutline}
|
.path=${mdiDeleteOutline}
|
||||||
@ -133,6 +138,13 @@ class DialogEntityAliases extends LitElement {
|
|||||||
this._aliases[index] = (ev.target as any).value;
|
this._aliases[index] = (ev.target as any).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _keyDownAlias(ev: KeyboardEvent) {
|
||||||
|
if (ev.key === "Enter") {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this._addAlias();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async _removeAlias(ev: Event) {
|
private async _removeAlias(ev: Event) {
|
||||||
const index = (ev.target as any).index;
|
const index = (ev.target as any).index;
|
||||||
const aliases = [...this._aliases];
|
const aliases = [...this._aliases];
|
||||||
|
@ -49,7 +49,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _submitting = false;
|
@state() private _submitting = false;
|
||||||
|
|
||||||
private _openAliasesSettings() {
|
private _handleAliasesClicked(ev: CustomEvent) {
|
||||||
|
if (ev.detail.index !== 0) return;
|
||||||
showEntityAliasesDialog(this, {
|
showEntityAliasesDialog(this, {
|
||||||
entity: this.entry!,
|
entity: this.entry!,
|
||||||
updateEntry: async (updates) => {
|
updateEntry: async (updates) => {
|
||||||
@ -272,12 +273,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
|
|||||||
"ui.dialogs.entity_registry.editor.aliases_section"
|
"ui.dialogs.entity_registry.editor.aliases_section"
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<mwc-list class="aliases">
|
<mwc-list class="aliases" @action=${this._handleAliasesClicked}>
|
||||||
<mwc-list-item
|
<mwc-list-item .twoline=${this.entry.aliases.length > 0} hasMeta>
|
||||||
.twoline=${this.entry.aliases.length > 0}
|
|
||||||
hasMeta
|
|
||||||
@click=${this._openAliasesSettings}
|
|
||||||
>
|
|
||||||
<span>
|
<span>
|
||||||
${this.entry.aliases.length > 0
|
${this.entry.aliases.length > 0
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
|
@ -807,12 +807,8 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
"ui.dialogs.entity_registry.editor.aliases_section"
|
"ui.dialogs.entity_registry.editor.aliases_section"
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<mwc-list class="aliases">
|
<mwc-list class="aliases" @action=${this._handleAliasesClicked}>
|
||||||
<mwc-list-item
|
<mwc-list-item .twoline=${this.entry.aliases.length > 0} hasMeta>
|
||||||
.twoline=${this.entry.aliases.length > 0}
|
|
||||||
hasMeta
|
|
||||||
@click=${this._openAliasesSettings}
|
|
||||||
>
|
|
||||||
<span>
|
<span>
|
||||||
${this.entry.aliases.length > 0
|
${this.entry.aliases.length > 0
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
@ -1015,7 +1011,8 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _openAliasesSettings() {
|
private _handleAliasesClicked(ev: CustomEvent) {
|
||||||
|
if (ev.detail.index !== 0) return;
|
||||||
showEntityAliasesDialog(this, {
|
showEntityAliasesDialog(this, {
|
||||||
entity: this.entry!,
|
entity: this.entry!,
|
||||||
updateEntry: async (updates) => {
|
updateEntry: async (updates) => {
|
||||||
|
@ -1003,7 +1003,8 @@
|
|||||||
"aliases": {
|
"aliases": {
|
||||||
"heading": "{name} aliases",
|
"heading": "{name} aliases",
|
||||||
"description": "Aliases are alternative names used in voice assistants to refer to this entity.",
|
"description": "Aliases are alternative names used in voice assistants to refer to this entity.",
|
||||||
"remove_alias": "Remove alias",
|
"remove_alias": "Remove alias {number}",
|
||||||
|
"input_label": "Alias {number}",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"add_alias": "Add alias",
|
"add_alias": "Add alias",
|
||||||
"no_aliases": "No aliases have been added yet",
|
"no_aliases": "No aliases have been added yet",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user