From dc27871189627c6c5bf17e01b48865ff6a20b8b0 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 9 Feb 2022 23:36:16 +0100 Subject: [PATCH] Set button role on button card and handle enter and space (#11627) --- src/panels/lovelace/cards/hui-button-card.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/panels/lovelace/cards/hui-button-card.ts b/src/panels/lovelace/cards/hui-button-card.ts index a490f9277c..f96a1d9201 100644 --- a/src/panels/lovelace/cards/hui-button-card.ts +++ b/src/panels/lovelace/cards/hui-button-card.ts @@ -160,9 +160,13 @@ export class HuiButtonCard extends LitElement implements LovelaceCard { hasHold: hasAction(this._config!.hold_action), hasDoubleClick: hasAction(this._config!.double_tap_action), })} + role="button" + aria-label=${this._config.name || + (stateObj ? computeStateName(stateObj) : "")} tabindex=${ifDefined( hasAction(this._config.tap_action) ? "0" : undefined )} + @keydown=${this._handleKeyDown} > ${this._config.show_icon ? html` @@ -230,6 +234,12 @@ 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);