Compare commits

...
Author SHA1 Message Date
Maarten Lakerveld 7e780ceae7 Make the onboarding location search usable with a screen reader
Enter on a search result or in the country picker no longer finishes
the step: the host-wide Enter listeners in onboarding-location and
onboarding-core-config are gone, so only the Next button saves.

A polite status region announces the result count, no results, and the
selected place. The visible "No results" text is localized.

The search field becomes readonly instead of disabled while searching,
so it keeps focus. Pressing the search or detect button moves focus to
the field with select(), because focus() on ha-input is a no-op while
its slotted button holds focus, and the button is replaced by a spinner.
2026-11-19 11:42:02 +01:00
3 changed files with 74 additions and 38 deletions

No files matched your search

+1 -10
View File
@@ -1,4 +1,4 @@
import type { PropertyValues, TemplateResult } from "lit";
import type { TemplateResult } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -121,15 +121,6 @@ class OnboardingCoreConfig extends LitElement {
`;
}
protected firstUpdated(changedProps: PropertyValues<this>) {
super.firstUpdated(changedProps);
this.addEventListener("keyup", (ev) => {
if (this._location && ev.key === "Enter") {
this._save(ev);
}
});
}
private _handleFormChanged(
ev: ValueChangedEvent<{ country?: string; time_zone?: string }>
) {
+72 -28
View File
@@ -25,6 +25,7 @@ import type { HaInput } from "../components/input/ha-input";
import "../components/item/ha-list-item-base";
import "../components/item/ha-list-item-button";
import "../components/list/ha-list-base";
import { searchResultsStatus } from "../components/list/search-results-status";
import "../components/map/ha-locations-editor";
import type {
HaLocationsEditor,
@@ -42,6 +43,29 @@ const AMSTERDAM: [number, number] = [52.3731339, 4.8903147];
const darkMql = matchMedia("(prefers-color-scheme: dark)");
const LOCATION_MARKER_ID = "location";
const placeLabels = (place: OpenStreetMapPlace): [string, string] => {
const primary = [
place.name || place.address[place.category],
place.address.house_number,
place.address.road || place.address.waterway,
place.address.village || place.address.town,
place.address.suburb || place.address.subdivision,
place.address.city || place.address.municipality,
]
.filter(Boolean)
.join(", ");
const secondary = [
place.address.county ||
place.address.state_district ||
place.address.region,
place.address.state,
place.address.country,
]
.filter(Boolean)
.join(", ");
return [primary, secondary];
};
@customElement("onboarding-location")
class OnboardingLocation extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@@ -60,6 +84,10 @@ class OnboardingLocation extends LitElement {
@state() private _search = false;
@state() private _searchTerm = "";
@state() private _status?: string;
@state() private _highlightedMarker?: number;
private _elevation?: string;
@@ -74,7 +102,7 @@ class OnboardingLocation extends LitElement {
@query("ha-locations-editor", true) private map!: HaLocationsEditor;
@query("ha-input") private _input?: HTMLElement;
@query("ha-input") private _input?: HaInput;
protected render(): TemplateResult {
const addressAttribution = this._localize(
@@ -118,7 +146,7 @@ class OnboardingLocation extends LitElement {
label=${this._localize(
"ui.panel.page-onboarding.core-config.address_label"
)}
.disabled=${this._working}
.readonly=${this._working}
@keyup=${this._addressSearch}
>
<ha-svg-icon slot="start" .path=${mdiMagnify}></ha-svg-icon>
@@ -147,29 +175,12 @@ class OnboardingLocation extends LitElement {
aria-label=${this._localize(
"ui.panel.page-onboarding.core-config.search_results"
)}
aria-busy=${this._working ? "true" : "false"}
>
${
this._places?.length
? this._places.map((place) => {
const primary = [
place.name || place.address[place.category],
place.address.house_number,
place.address.road || place.address.waterway,
place.address.village || place.address.town,
place.address.suburb || place.address.subdivision,
place.address.city || place.address.municipality,
]
.filter(Boolean)
.join(", ");
const secondary = [
place.address.county ||
place.address.state_district ||
place.address.region,
place.address.state,
place.address.country,
]
.filter(Boolean)
.join(", ");
const [primary, secondary] = placeLabels(place);
return html`<ha-list-item-button
@click=${this._itemClicked}
.placeId=${place.place_id}
@@ -187,7 +198,16 @@ class OnboardingLocation extends LitElement {
})
: html`<ha-list-item-base>
<span slot="headline"
>${this._places === null ? "" : "No results"}</span
>${
this._places === null
? ""
: searchResultsStatus(
this._searchTerm,
this._places,
() => true,
this._localize
)
}</span
>
</ha-list-item-base>`
}
@@ -195,6 +215,7 @@ class OnboardingLocation extends LitElement {
`
: nothing
}
<div class="visually-hidden" role="status">${this._status}</div>
</div>
<ha-locations-editor
class="flex"
@@ -224,11 +245,6 @@ class OnboardingLocation extends LitElement {
protected firstUpdated(changedProps: PropertyValues<this>) {
super.firstUpdated(changedProps);
setTimeout(() => this._input!.focus(), 100);
this.addEventListener("keyup", (ev) => {
if (ev.key === "Enter") {
this._save(ev);
}
});
}
protected updated(changedProps: PropertyValues) {
@@ -315,6 +331,7 @@ class OnboardingLocation extends LitElement {
)!;
this._location = [Number(place.lat), Number(place.lon)];
this._setCountry(place.address.country_code);
this._announceSelection(place);
}
private _itemClicked(ev) {
@@ -324,12 +341,20 @@ class OnboardingLocation extends LitElement {
)!;
this._location = [Number(place.lat), Number(place.lon)];
this._setCountry(place.address.country_code);
this._announceSelection(place);
}
private _announceSelection(place: OpenStreetMapPlace) {
this._status = this._localize(
"ui.panel.page-onboarding.core-config.selected_location",
{ location: placeLabels(place).filter(Boolean).join(", ") }
);
}
private async _addressSearch(ev: KeyboardEvent) {
ev.stopPropagation();
this._search = ((ev.currentTarget as HaInput).value ?? "").length > 0;
if (ev.key !== "Enter") {
if (ev.key !== "Enter" || this._working) {
return;
}
this._searchAddress((ev.currentTarget as HaInput).value ?? "");
@@ -339,6 +364,8 @@ class OnboardingLocation extends LitElement {
this._working = true;
this._highlightedMarker = undefined;
this._error = undefined;
this._status = undefined;
this._searchTerm = address;
this._places = null;
this.map.addEventListener(
"markers-updated",
@@ -364,6 +391,12 @@ class OnboardingLocation extends LitElement {
this._setCountry(this._places[0].address.country_code);
this._elevation = undefined;
}
this._status = searchResultsStatus(
address,
this._places,
() => true,
this._localize
);
} catch (e: any) {
this._places = undefined;
this._error = e.message;
@@ -381,6 +414,7 @@ class OnboardingLocation extends LitElement {
this._setCountry(reverse.address.country_code);
this._places = [reverse];
this._highlightedMarker = reverse.place_id;
this._announceSelection(reverse);
}
private _setCountry(countryCode: string) {
@@ -392,6 +426,7 @@ class OnboardingLocation extends LitElement {
}
private async _handleButtonClick(ev) {
this._input?.select();
if (this._search) {
this._searchAddress(ev.target.parentElement.value);
return;
@@ -553,6 +588,15 @@ class OnboardingLocation extends LitElement {
.attribution a {
color: inherit;
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
`,
];
}
+1
View File
@@ -13079,6 +13079,7 @@
"location_name_default": "Home",
"address_label": "Search address",
"search_results": "Search results",
"selected_location": "Selected {location}",
"button_detect": "Detect",
"finish": "Next"
},