mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Set button role on button card and handle enter and space (#11627)
This commit is contained in:
parent
9c9bfa2b77
commit
dc27871189
@ -160,9 +160,13 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
hasHold: hasAction(this._config!.hold_action),
|
hasHold: hasAction(this._config!.hold_action),
|
||||||
hasDoubleClick: hasAction(this._config!.double_tap_action),
|
hasDoubleClick: hasAction(this._config!.double_tap_action),
|
||||||
})}
|
})}
|
||||||
|
role="button"
|
||||||
|
aria-label=${this._config.name ||
|
||||||
|
(stateObj ? computeStateName(stateObj) : "")}
|
||||||
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`
|
||||||
@ -230,6 +234,12 @@ 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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user