Fix accessibility of settings and system navigation (#12845)

This commit is contained in:
Steve Repsher 2022-08-23 23:45:44 -04:00 committed by GitHub
parent be169f9c83
commit a1bc748bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 27 deletions

View File

@ -1,11 +1,12 @@
import "@material/mwc-list/mwc-list";
import "@material/mwc-list/mwc-list-item";
import { ActionDetail } from "@material/mwc-list/mwc-list";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { navigate } from "../common/navigate";
import type { PageNavigation } from "../layouts/hass-tabs-subpage";
import type { HomeAssistant } from "../types";
import "./ha-clickable-list-item";
import "./ha-icon-next";
import "./ha-list-item";
import "./ha-svg-icon";
@customElement("ha-navigation-list")
@ -18,17 +19,22 @@ class HaNavigationList extends LitElement {
@property({ type: Boolean }) public hasSecondary = false;
@property() public label?: string;
public render(): TemplateResult {
return html`
<mwc-list>
<mwc-list
innerRole="menu"
itemRoles="menuitem"
innerAriaLabel=${ifDefined(this.label)}
@action=${this._handleListAction}
>
${this.pages.map(
(page) => html`
<ha-clickable-list-item
<ha-list-item
graphic="avatar"
.twoline=${this.hasSecondary}
.hasMeta=${!this.narrow}
@click=${this._entryClicked}
href=${page.path}
>
<div
slot="graphic"
@ -44,15 +50,20 @@ class HaNavigationList extends LitElement {
${!this.narrow
? html`<ha-icon-next slot="meta"></ha-icon-next>`
: ""}
</ha-clickable-list-item>
</ha-list-item>
`
)}
</mwc-list>
`;
}
private _entryClicked(ev) {
ev.currentTarget.blur();
private _handleListAction(ev: CustomEvent<ActionDetail>) {
const path = this.pages[ev.detail.index].path;
if (path.endsWith("#external-app-configuration")) {
this.hass.auth.external!.fireMessage({ type: "config_screen/show" });
} else {
navigate(path);
}
}
static styles: CSSResultGroup = css`
@ -75,7 +86,7 @@ class HaNavigationList extends LitElement {
.icon-background ha-svg-icon {
color: #fff;
}
ha-clickable-list-item {
ha-list-item {
cursor: pointer;
font-size: var(--navigation-list-item-title-font-size);
padding: var(--navigation-list-item-padding) 0;

View File

@ -137,6 +137,9 @@ class HaConfigSystemNavigation extends LitElement {
.narrow=${this.narrow}
.pages=${pages}
hasSecondary
.label=${this.hass.localize(
"ui.panel.config.dashboard.system.main"
)}
></ha-navigation-list>
</ha-card>
</ha-config-section>

View File

@ -60,26 +60,11 @@ class HaConfigNavigation extends LitElement {
.hass=${this.hass}
.narrow=${this.narrow}
.pages=${pages}
@click=${this._entryClicked}
.label=${this.hass.localize("panel.config")}
></ha-navigation-list>
`;
}
private _entryClicked(ev) {
const anchor = ev
.composedPath()
.find((n) => (n as HTMLElement).tagName === "A") as
| HTMLAnchorElement
| undefined;
if (anchor?.href?.endsWith("#external-app-configuration")) {
ev.preventDefault();
this.hass.auth.external!.fireMessage({
type: "config_screen/show",
});
}
}
static styles: CSSResultGroup = css`
ha-navigation-list {
--navigation-list-item-title-font-size: 16px;