mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix keyboard keys for tap action (#14071)
This commit is contained in:
parent
0b76b60f6e
commit
9ea0e3a75f
@ -166,7 +166,6 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
||||
tabindex=${ifDefined(
|
||||
hasAction(this._config.tap_action) ? "0" : undefined
|
||||
)}
|
||||
@keydown=${this._handleKeyDown}
|
||||
>
|
||||
${this._config.show_icon
|
||||
? html`
|
||||
@ -234,12 +233,6 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
||||
return this._ripple;
|
||||
});
|
||||
|
||||
private _handleKeyDown(ev: KeyboardEvent) {
|
||||
if (ev.key === "Enter" || ev.key === " ") {
|
||||
handleAction(this, this.hass!, this._config!, "tap");
|
||||
}
|
||||
}
|
||||
|
||||
@eventOptions({ passive: true })
|
||||
private handleRippleActivate(evt?: Event) {
|
||||
this._rippleHandlers.startPress(evt);
|
||||
|
@ -30,7 +30,7 @@ interface ActionHandlerElement extends HTMLElement {
|
||||
options: ActionHandlerOptions;
|
||||
start?: (ev: Event) => void;
|
||||
end?: (ev: Event) => void;
|
||||
handleEnter?: (ev: KeyboardEvent) => void;
|
||||
handleKeyDown?: (ev: KeyboardEvent) => void;
|
||||
};
|
||||
}
|
||||
|
||||
@ -117,7 +117,10 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
||||
element.removeEventListener("mousedown", element.actionHandler.start!);
|
||||
element.removeEventListener("click", element.actionHandler.end!);
|
||||
|
||||
element.removeEventListener("keyup", element.actionHandler.handleEnter!);
|
||||
element.removeEventListener(
|
||||
"keydown",
|
||||
element.actionHandler.handleKeyDown!
|
||||
);
|
||||
} else {
|
||||
element.addEventListener("contextmenu", (ev: Event) => {
|
||||
const e = ev || window.event;
|
||||
@ -196,8 +199,8 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
||||
}
|
||||
};
|
||||
|
||||
element.actionHandler.handleEnter = (ev: KeyboardEvent) => {
|
||||
if (ev.keyCode !== 13) {
|
||||
element.actionHandler.handleKeyDown = (ev: KeyboardEvent) => {
|
||||
if (!["Enter", " "].includes(ev.key)) {
|
||||
return;
|
||||
}
|
||||
(ev.currentTarget as ActionHandlerElement).actionHandler!.end!(ev);
|
||||
@ -214,7 +217,7 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
||||
});
|
||||
element.addEventListener("click", element.actionHandler.end);
|
||||
|
||||
element.addEventListener("keyup", element.actionHandler.handleEnter);
|
||||
element.addEventListener("keydown", element.actionHandler.handleKeyDown);
|
||||
}
|
||||
|
||||
private startAnimation(x: number, y: number) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user