From 5c2fcd7f9b6cedaee3b51ec74cb7febc5ae719e6 Mon Sep 17 00:00:00 2001 From: Gia Ferrari Date: Wed, 28 Dec 2022 17:16:05 -0800 Subject: [PATCH] Add alt attribute to various images (#14405) * ha-config-area-page: Add alt tag for area-picture * dialog-tag-detail: Add alt tag for generated QR code image. * ha-config-hardware: Blank alt tag for hardware pic, info already elsewhere * dialog-energy-solar-settings: Blank alt tag for brand icon. * ha-energy-grid-settings: Blank alt tag for co2signal brand icon. * Add a few more appropriately-blank alt texts. * ha-config-device-page: Logo alt text set to name of device domain. * ha-config-repairs: Logo alt text set to name of issue domain. * hui-picture-card(-editor): Alternate Text via config (blank default) * hui-picture-entity-card(-editor): Alternate Text via config (blank default) * ha-long-lived-access-token-dialog: Alt text for QR code. * hui-picture-header-footer: Support alt text via optional property. * A few more blank alt attributes. * ha-tile-image: Support alt tag (but it is blank in current usage). * prod cla-bot * Lint. Fix whitespace. * Add missing alt text properties to TS types. * Fix my silly typo in picture-entity-card-editor's SCHEMA (+ minor reformat) * Add alt_text to Picture(Entity)CardConfig TypeScript types. * Format with prettier. * Revise alt text for tag QR * Revise alt text for token QR * Revise alternate to alternative * Add alt to logo in gallery * Add alt text to crop image * Use ifDefined for tile image alt * Change area picture alt to area name * Remove entry from entities config struct * Revert altText changes for Picture Entity Card (to revisit in future PR) See: https://github.com/home-assistant/frontend/pull/14405#discussion_r1032735871 * Revert changes to hui-image and picture entity editor Co-authored-by: Steve Repsher --- gallery/src/pages/components/ha-alert.ts | 4 +++- hassio/src/addon-view/info/hassio-addon-info.ts | 1 + src/components/ha-addon-picker.ts | 6 +++++- src/components/ha-config-entry-picker.ts | 1 + src/components/tile/ha-tile-image.ts | 7 ++++++- .../image-cropper-dialog/image-cropper-dialog.ts | 2 +- src/onboarding/integration-badge.ts | 1 + src/panels/config/areas/ha-config-area-page.ts | 3 ++- .../config/devices/ha-config-device-page.ts | 4 ++++ .../energy/components/ha-energy-grid-settings.ts | 2 ++ .../dialogs/dialog-energy-solar-settings.ts | 1 + src/panels/config/hardware/ha-config-hardware.ts | 2 +- .../config/integrations/ha-domain-integrations.ts | 1 + .../config/integrations/ha-integration-header.ts | 1 + .../integrations/ha-integration-list-item.ts | 1 + src/panels/config/repairs/ha-config-repairs.ts | 1 + .../config/repairs/integrations-startup-time.ts | 1 + src/panels/config/tags/dialog-tag-detail.ts | 9 ++++++++- src/panels/lovelace/cards/hui-picture-card.ts | 5 ++++- src/panels/lovelace/cards/types.ts | 1 + .../config-elements/hui-picture-card-editor.ts | 15 +++++++++++++++ .../header-footer/hui-picture-header-footer.ts | 1 + src/panels/lovelace/header-footer/structs.ts | 1 + src/panels/lovelace/header-footer/types.ts | 1 + .../profile/ha-long-lived-access-token-dialog.ts | 9 ++++++++- src/translations/en.json | 8 ++++++-- 26 files changed, 78 insertions(+), 11 deletions(-) diff --git a/gallery/src/pages/components/ha-alert.ts b/gallery/src/pages/components/ha-alert.ts index ced4c5a44b..a0d3f309fb 100644 --- a/gallery/src/pages/components/ha-alert.ts +++ b/gallery/src/pages/components/ha-alert.ts @@ -98,7 +98,9 @@ const alerts: { description: "Alert with slotted image", type: "warning", iconSlot: html`Home Assistant logo`, }, { diff --git a/hassio/src/addon-view/info/hassio-addon-info.ts b/hassio/src/addon-view/info/hassio-addon-info.ts index 3cc3d23010..a6e8c99217 100644 --- a/hassio/src/addon-view/info/hassio-addon-info.ts +++ b/hassio/src/addon-view/info/hassio-addon-info.ts @@ -404,6 +404,7 @@ class HassioAddonInfo extends LitElement { ? html` ` diff --git a/src/components/ha-addon-picker.ts b/src/components/ha-addon-picker.ts index 955bb6fefb..8c765d9755 100644 --- a/src/components/ha-addon-picker.ts +++ b/src/components/ha-addon-picker.ts @@ -16,7 +16,11 @@ const rowRenderer: ComboBoxLitRenderer = ( ${item.name} ${item.slug} ${item.icon - ? html`` + ? html`` : ""} `; diff --git a/src/components/ha-config-entry-picker.ts b/src/components/ha-config-entry-picker.ts index 7bd4301bfe..09bfc45b4e 100644 --- a/src/components/ha-config-entry-picker.ts +++ b/src/components/ha-config-entry-picker.ts @@ -59,6 +59,7 @@ class HaConfigEntryPicker extends LitElement { > ${item.localized_domain_name} - ${this.imageUrl ? html`` : null} + ${this.imageUrl + ? html`${ifDefined(this.imageAlt)}` + : null} `; } diff --git a/src/dialogs/image-cropper-dialog/image-cropper-dialog.ts b/src/dialogs/image-cropper-dialog/image-cropper-dialog.ts index 74e3711235..94b6d22065 100644 --- a/src/dialogs/image-cropper-dialog/image-cropper-dialog.ts +++ b/src/dialogs/image-cropper-dialog/image-cropper-dialog.ts @@ -74,7 +74,7 @@ export class HaImagecropperDialog extends LitElement { round: Boolean(this._params?.options.round), })}" > - + ${this.hass.localize("ui.dialogs.image_cropper.crop_image")} ${this.hass.localize("ui.common.cancel")} diff --git a/src/onboarding/integration-badge.ts b/src/onboarding/integration-badge.ts index 62e48d1b00..fc440b1589 100644 --- a/src/onboarding/integration-badge.ts +++ b/src/onboarding/integration-badge.ts @@ -19,6 +19,7 @@ class IntegrationBadge extends LitElement { return html`
${area.picture ? html`
- + ${imageURL - ? html`` + ? html`` : ""} ${boardName || diff --git a/src/panels/config/integrations/ha-domain-integrations.ts b/src/panels/config/integrations/ha-domain-integrations.ts index 32a281247f..f62461b553 100644 --- a/src/panels/config/integrations/ha-domain-integrations.ts +++ b/src/panels/config/integrations/ha-domain-integrations.ts @@ -48,6 +48,7 @@ class HaDomainIntegrations extends LitElement { hasMeta >
${domainToName(this.hass.localize, `; + this._qrCode = html`${this.hass.localize(`; } static get styles(): CSSResultGroup { diff --git a/src/panels/lovelace/cards/hui-picture-card.ts b/src/panels/lovelace/cards/hui-picture-card.ts index 20a2a2f315..ffcf4f5009 100644 --- a/src/panels/lovelace/cards/hui-picture-card.ts +++ b/src/panels/lovelace/cards/hui-picture-card.ts @@ -101,7 +101,10 @@ export class HuiPictureCard extends LitElement implements LovelaceCard { ), })} > - + ${this._config.alt_text} `; } diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index 5ab627b466..2ad69eeb94 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -332,6 +332,7 @@ export interface PictureCardConfig extends LovelaceCardConfig { hold_action?: ActionConfig; double_tap_action?: ActionConfig; theme?: string; + alt_text?: string; } export interface PictureElementsCardConfig extends LovelaceCardConfig { diff --git a/src/panels/lovelace/editor/config-elements/hui-picture-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-picture-card-editor.ts index 8174a049e2..ee75869fc6 100644 --- a/src/panels/lovelace/editor/config-elements/hui-picture-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-picture-card-editor.ts @@ -20,6 +20,7 @@ const cardConfigStruct = assign( tap_action: optional(actionConfigStruct), hold_action: optional(actionConfigStruct), theme: optional(string()), + alt_text: optional(string()), }) ); @@ -53,6 +54,10 @@ export class HuiPictureCardEditor return this._config!.theme || ""; } + get _alt_text(): string { + return this._config!.alt_text || ""; + } + protected render(): TemplateResult { if (!this.hass || !this._config) { return html``; @@ -72,6 +77,16 @@ export class HuiPictureCardEditor .configValue=${"image"} @input=${this._valueChanged} > + `; + this._qrCode = html`${this.hass.localize(`; } static get styles(): CSSResultGroup { diff --git a/src/translations/en.json b/src/translations/en.json index a6329fb139..f0b5e00104 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -791,7 +791,8 @@ "close": "Close" }, "image_cropper": { - "crop": "Crop" + "crop": "Crop", + "crop_image": "Picture to crop" }, "date-picker": { "today": "Today" @@ -1435,6 +1436,7 @@ "confirm_remove_title": "Remove tag?", "confirm_remove": "Are you sure you want to remove tag {tag}?", "automation_title": "Tag {name} is scanned", + "qr_code_image": "QR code for tag {name}", "headers": { "icon": "Icon", "name": "Name", @@ -4195,6 +4197,7 @@ "description": "The Light card allows you to change the brightness of the light." }, "generic": { + "alt_text": "Alternative Text", "aspect_ratio": "Aspect Ratio", "attribute": "Attribute", "camera_image": "Camera Entity", @@ -4598,7 +4601,8 @@ "name": "Name", "prompt_name": "Give the token a name", "prompt_copy_token": "Copy your access token. It will not be shown again.", - "empty_state": "You have no long-lived access tokens yet." + "empty_state": "You have no long-lived access tokens yet.", + "qr_code_image": "QR code for token {name}" } }, "shopping_list": {