Skip to content

Commit 9b48cd7

Browse files
Add trigger/condition/action dialog: select single search result with enter key (#27825)
* Add trigger/condition/action dialog: select single search result with enter key * Update src/panels/config/automation/add-automation-element-dialog.ts --------- Co-authored-by: Petar Petrov <[email protected]>
1 parent 11c6f6e commit 9b48cd7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/panels/config/automation/add-automation-element-dialog.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ class DialogAddAutomationElement
10541054
private _onSearchFocus(ev) {
10551055
this._removeKeyboardShortcuts = tinykeys(ev.target, {
10561056
ArrowDown: this._focusSearchList,
1057+
Enter: this._pickSingleItem,
10571058
});
10581059
}
10591060

@@ -1070,6 +1071,39 @@ class DialogAddAutomationElement
10701071
this._itemsListFirstElement.focus();
10711072
};
10721073

1074+
private _pickSingleItem = (ev: KeyboardEvent) => {
1075+
if (!this._filter) {
1076+
return;
1077+
}
1078+
1079+
ev.preventDefault();
1080+
const automationElementType = this._params!.type;
1081+
1082+
const items = [
1083+
...this._getFilteredItems(
1084+
automationElementType,
1085+
this._filter,
1086+
this.hass.localize,
1087+
this.hass.services,
1088+
this._manifests
1089+
),
1090+
...(automationElementType !== "trigger"
1091+
? this._getFilteredBuildingBlocks(
1092+
automationElementType,
1093+
this._filter,
1094+
this.hass.localize
1095+
)
1096+
: []),
1097+
];
1098+
1099+
if (items.length !== 1) {
1100+
return;
1101+
}
1102+
1103+
this._params!.add(items[0].key);
1104+
this.closeDialog();
1105+
};
1106+
10731107
static get styles(): CSSResultGroup {
10741108
return [
10751109
css`

0 commit comments

Comments
 (0)