Add tooltips and aria-labels to media player buttons (#10881)

This commit is contained in:
Philip Allgaier 2021-12-14 01:33:34 +01:00 committed by GitHub
parent 86114758c3
commit d8e12f4280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 9 deletions

View File

@ -156,6 +156,7 @@ export interface MediaPlayerThumbnail {
export interface ControlButton { export interface ControlButton {
icon: string; icon: string;
// Used as key for action as well as tooltip and aria-label translation key
action: string; action: string;
} }

View File

@ -65,6 +65,9 @@ class MoreInfoMediaPlayer extends LitElement {
action=${control.action} action=${control.action}
@click=${this._handleClick} @click=${this._handleClick}
.path=${control.icon} .path=${control.icon}
.label=${this.hass.localize(
`ui.card.media_player.${control.action}`
)}
> >
</ha-icon-button> </ha-icon-button>
` `

View File

@ -235,6 +235,9 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
<div> <div>
<ha-icon-button <ha-icon-button
.path=${mdiDotsVertical} .path=${mdiDotsVertical}
.label=${this.hass.localize(
"ui.panel.lovelace.cards.show_more_info"
)}
class="more-info" class="more-info"
@click=${this._handleMoreInfo} @click=${this._handleMoreInfo}
></ha-icon-button> ></ha-icon-button>

View File

@ -30,6 +30,7 @@ import "../../../components/ha-slider";
import { UNAVAILABLE, UNAVAILABLE_STATES, UNKNOWN } from "../../../data/entity"; import { UNAVAILABLE, UNAVAILABLE_STATES, UNKNOWN } from "../../../data/entity";
import { import {
computeMediaDescription, computeMediaDescription,
ControlButton,
MediaPlayerEntity, MediaPlayerEntity,
SUPPORT_NEXT_TRACK, SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE, SUPPORT_PAUSE,
@ -108,6 +109,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
} }
const entityState = stateObj.state; const entityState = stateObj.state;
const controlButton = this._computeControlButton(stateObj);
const buttons = html` const buttons = html`
${!this._narrow && ${!this._narrow &&
@ -116,6 +118,9 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${mdiSkipPrevious} .path=${mdiSkipPrevious}
.label=${this.hass.localize(
"ui.card.media_player.media_previous_track"
)}
@click=${this._previousTrack} @click=${this._previousTrack}
></ha-icon-button> ></ha-icon-button>
` `
@ -130,7 +135,10 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
supportsFeature(stateObj, SUPPORT_PAUSE))) supportsFeature(stateObj, SUPPORT_PAUSE)))
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${this._computeControlIcon(stateObj)} .path=${controlButton.icon}
.label=${this.hass.localize(
`ui.card.media_player.${controlButton.action}`
)}
@click=${this._playPauseStop} @click=${this._playPauseStop}
></ha-icon-button> ></ha-icon-button>
` `
@ -140,6 +148,9 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${mdiSkipNext} .path=${mdiSkipNext}
.label=${this.hass.localize(
"ui.card.media_player.media_next_track"
)}
@click=${this._nextTrack} @click=${this._nextTrack}
></ha-icon-button> ></ha-icon-button>
` `
@ -162,6 +173,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${mdiPower} .path=${mdiPower}
.label=${this.hass.localize("ui.card.media_player.turn_on")}
@click=${this._togglePower} @click=${this._togglePower}
></ha-icon-button> ></ha-icon-button>
` `
@ -175,6 +187,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${mdiPower} .path=${mdiPower}
.label=${this.hass.localize("ui.card.media_player.turn_off")}
@click=${this._togglePower} @click=${this._togglePower}
></ha-icon-button> ></ha-icon-button>
` `
@ -193,6 +206,13 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
.path=${stateObj.attributes.is_volume_muted .path=${stateObj.attributes.is_volume_muted
? mdiVolumeOff ? mdiVolumeOff
: mdiVolumeHigh} : mdiVolumeHigh}
.label=${this.hass.localize(
`ui.card.media_player.${
stateObj.attributes.is_volume_muted
? "media_volume_mute"
: "media_volume_unmute"
}`
)}
@click=${this._toggleMute} @click=${this._toggleMute}
></ha-icon-button> ></ha-icon-button>
` `
@ -214,10 +234,16 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? html` ? html`
<ha-icon-button <ha-icon-button
.path=${mdiVolumeMinus} .path=${mdiVolumeMinus}
.label=${this.hass.localize(
"ui.card.media_player.media_volume_down"
)}
@click=${this._volumeDown} @click=${this._volumeDown}
></ha-icon-button> ></ha-icon-button>
<ha-icon-button <ha-icon-button
.path=${mdiVolumePlus} .path=${mdiVolumePlus}
.label=${this.hass.localize(
"ui.card.media_player.media_volume_up"
)}
@click=${this._volumeUp} @click=${this._volumeUp}
></ha-icon-button> ></ha-icon-button>
` `
@ -249,14 +275,14 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
this._veryNarrow = (this.clientWidth || 0) < 225; this._veryNarrow = (this.clientWidth || 0) < 225;
} }
private _computeControlIcon(stateObj: HassEntity): string { private _computeControlButton(stateObj: HassEntity): ControlButton {
return stateObj.state === "on" return stateObj.state === "on"
? mdiPlayPause ? { icon: mdiPlayPause, action: "media_play_pause" }
: stateObj.state !== "playing" : stateObj.state !== "playing"
? mdiPlay ? { icon: mdiPlay, action: "media_play" }
: supportsFeature(stateObj, SUPPORT_PAUSE) : supportsFeature(stateObj, SUPPORT_PAUSE)
? mdiPause ? { icon: mdiPause, action: "media_pause" }
: mdiStop; : { icon: mdiStop, action: "media_stop" };
} }
private _togglePower(): void { private _togglePower(): void {

View File

@ -195,8 +195,14 @@
"turn_off": "Turn off", "turn_off": "Turn off",
"media_play": "Play", "media_play": "Play",
"media_play_pause": "Play/pause", "media_play_pause": "Play/pause",
"media_next_track": "Next", "media_pause": "Pause",
"media_previous_track": "Previous", "media_stop": "Stop",
"media_next_track": "Next track",
"media_previous_track": "Previous track",
"media_volume_up": "Volume up",
"media_volume_down": "Volume down",
"media_volume_mute": "Volume mute",
"media_volume_unmute": "Volume unmute",
"text_to_speak": "Text to speak" "text_to_speak": "Text to speak"
}, },
"persistent_notification": { "persistent_notification": {
@ -689,7 +695,7 @@
"close_cover": "Close cover", "close_cover": "Close cover",
"open_tilt_cover": "Open cover tilt", "open_tilt_cover": "Open cover tilt",
"close_tilt_cover": "Close cover tilt", "close_tilt_cover": "Close cover tilt",
"stop_cover": "Stop cover from moving" "stop_cover": "Stop cover"
} }
}, },
"entity_registry": { "entity_registry": {