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 <MindFreeze@users.noreply.github.com>
This commit is contained in:
Wendelin
2025-11-06 14:46:53 +01:00
committed by GitHub
parent 11c6f6ec78
commit 9b48cd7737

View File

@@ -1054,6 +1054,7 @@ class DialogAddAutomationElement
private _onSearchFocus(ev) {
this._removeKeyboardShortcuts = tinykeys(ev.target, {
ArrowDown: this._focusSearchList,
Enter: this._pickSingleItem,
});
}
@@ -1070,6 +1071,39 @@ class DialogAddAutomationElement
this._itemsListFirstElement.focus();
};
private _pickSingleItem = (ev: KeyboardEvent) => {
if (!this._filter) {
return;
}
ev.preventDefault();
const automationElementType = this._params!.type;
const items = [
...this._getFilteredItems(
automationElementType,
this._filter,
this.hass.localize,
this.hass.services,
this._manifests
),
...(automationElementType !== "trigger"
? this._getFilteredBuildingBlocks(
automationElementType,
this._filter,
this.hass.localize
)
: []),
];
if (items.length !== 1) {
return;
}
this._params!.add(items[0].key);
this.closeDialog();
};
static get styles(): CSSResultGroup {
return [
css`