Add title attributes to iframes for accessibility (#14760)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Steve Repsher 2022-12-14 10:50:14 -05:00 committed by GitHub
parent c400e771cb
commit 311d11f2da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 18 deletions

View File

@ -59,7 +59,11 @@ class HassioIngressView extends LitElement {
return html` <hass-loading-screen></hass-loading-screen> `; return html` <hass-loading-screen></hass-loading-screen> `;
} }
const iframe = html`<iframe src=${this._addon.ingress_url!}></iframe>`; const iframe = html`<iframe
.title=${this._addon.name}
.src=${this._addon.ingress_url!}
>
</iframe>`;
if (!this.ingressPanel) { if (!this.ingressPanel) {
return html`<hass-subpage return html`<hass-subpage

View File

@ -12,6 +12,9 @@ import {
import { setCustomPanelProperties } from "../../util/custom-panel/set-custom-panel-properties"; import { setCustomPanelProperties } from "../../util/custom-panel/set-custom-panel-properties";
declare global { declare global {
interface HTMLElementTagNameMap {
"ha-panel-custom": HaPanelCustom;
}
interface Window { interface Window {
customPanel: HaPanelCustom | undefined; customPanel: HaPanelCustom | undefined;
} }
@ -140,18 +143,18 @@ export class HaPanelCustom extends ReactiveElement {
} }
window.customPanel = this; window.customPanel = this;
const titleAttr = this.panel.title ? `title="${this.panel.title}"` : "";
this.innerHTML = ` this.innerHTML = `
<style> <style>
iframe { iframe {
border: 0; border: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block; display: block;
background-color: var(--primary-background-color); background-color: var(--primary-background-color);
} }
</style> </style>
<iframe></iframe> <iframe ${titleAttr}></iframe>`.trim();
`.trim();
const iframeDoc = this.querySelector("iframe")!.contentWindow!.document; const iframeDoc = this.querySelector("iframe")!.contentWindow!.document;
iframeDoc.open(); iframeDoc.open();
iframeDoc.write( iframeDoc.write(

View File

@ -1,5 +1,6 @@
import { html, css, LitElement } from "lit"; import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import "../../layouts/hass-error-screen"; import "../../layouts/hass-error-screen";
import "../../layouts/hass-subpage"; import "../../layouts/hass-subpage";
import { HomeAssistant, PanelInfo } from "../../types"; import { HomeAssistant, PanelInfo } from "../../types";
@ -35,11 +36,12 @@ class HaPanelIframe extends LitElement {
main-page main-page
> >
<iframe <iframe
title=${ifDefined(
this.panel.title === null ? undefined : this.panel.title
)}
src=${this.panel.config.url} src=${this.panel.config.url}
sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts allow-modals allow-downloads" sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts allow-modals allow-downloads"
allowfullscreen="true" allow="fullscreen"
webkitallowfullscreen="true"
mozallowfullscreen="true"
></iframe> ></iframe>
</hass-subpage> </hass-subpage>
`; `;

View File

@ -1,12 +1,13 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import parseAspectRatio from "../../../common/util/parse-aspect-ratio"; import parseAspectRatio from "../../../common/util/parse-aspect-ratio";
import "../../../components/ha-card";
import "../../../components/ha-alert"; import "../../../components/ha-alert";
import "../../../components/ha-card";
import type { HomeAssistant } from "../../../types";
import { LovelaceCard, LovelaceCardEditor } from "../types"; import { LovelaceCard, LovelaceCardEditor } from "../types";
import { IframeCardConfig } from "./types"; import { IframeCardConfig } from "./types";
import type { HomeAssistant } from "../../../types";
@customElement("hui-iframe-card") @customElement("hui-iframe-card")
export class HuiIframeCard extends LitElement implements LovelaceCard { export class HuiIframeCard extends LitElement implements LovelaceCard {
@ -88,9 +89,10 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
})} })}
> >
<iframe <iframe
title=${ifDefined(this._config.title)}
src=${this._config.url} src=${this._config.url}
sandbox="allow-forms allow-modals allow-popups allow-pointer-lock allow-same-origin allow-scripts" sandbox="allow-forms allow-modals allow-popups allow-pointer-lock allow-same-origin allow-scripts"
allowfullscreen="true" allow="fullscreen"
></iframe> ></iframe>
</div> </div>
</ha-card> </ha-card>