mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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(
|
tabindex=${ifDefined(
|
||||||
hasAction(this._config.tap_action) ? "0" : undefined
|
hasAction(this._config.tap_action) ? "0" : undefined
|
||||||
)}
|
)}
|
||||||
@keydown=${this._handleKeyDown}
|
|
||||||
>
|
>
|
||||||
${this._config.show_icon
|
${this._config.show_icon
|
||||||
? html`
|
? html`
|
||||||
@ -234,12 +233,6 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
return this._ripple;
|
return this._ripple;
|
||||||
});
|
});
|
||||||
|
|
||||||
private _handleKeyDown(ev: KeyboardEvent) {
|
|
||||||
if (ev.key === "Enter" || ev.key === " ") {
|
|
||||||
handleAction(this, this.hass!, this._config!, "tap");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@eventOptions({ passive: true })
|
@eventOptions({ passive: true })
|
||||||
private handleRippleActivate(evt?: Event) {
|
private handleRippleActivate(evt?: Event) {
|
||||||
this._rippleHandlers.startPress(evt);
|
this._rippleHandlers.startPress(evt);
|
||||||
|
@ -30,7 +30,7 @@ interface ActionHandlerElement extends HTMLElement {
|
|||||||
options: ActionHandlerOptions;
|
options: ActionHandlerOptions;
|
||||||
start?: (ev: Event) => void;
|
start?: (ev: Event) => void;
|
||||||
end?: (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("mousedown", element.actionHandler.start!);
|
||||||
element.removeEventListener("click", element.actionHandler.end!);
|
element.removeEventListener("click", element.actionHandler.end!);
|
||||||
|
|
||||||
element.removeEventListener("keyup", element.actionHandler.handleEnter!);
|
element.removeEventListener(
|
||||||
|
"keydown",
|
||||||
|
element.actionHandler.handleKeyDown!
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
element.addEventListener("contextmenu", (ev: Event) => {
|
element.addEventListener("contextmenu", (ev: Event) => {
|
||||||
const e = ev || window.event;
|
const e = ev || window.event;
|
||||||
@ -196,8 +199,8 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
element.actionHandler.handleEnter = (ev: KeyboardEvent) => {
|
element.actionHandler.handleKeyDown = (ev: KeyboardEvent) => {
|
||||||
if (ev.keyCode !== 13) {
|
if (!["Enter", " "].includes(ev.key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(ev.currentTarget as ActionHandlerElement).actionHandler!.end!(ev);
|
(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("click", element.actionHandler.end);
|
||||||
|
|
||||||
element.addEventListener("keyup", element.actionHandler.handleEnter);
|
element.addEventListener("keydown", element.actionHandler.handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
private startAnimation(x: number, y: number) {
|
private startAnimation(x: number, y: number) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user