Fix language picker in profile displaying wrong language (#17725)

* fix language picker when changing language sort order #16642

* alternative fix
This commit is contained in:
karwosts 2023-08-29 00:45:54 -07:00 committed by GitHub
parent 916a6df39b
commit 166acee1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,7 +41,18 @@ export class HaLanguagePicker extends LitElement {
protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
if (changedProperties.has("languages") || changedProperties.has("value")) {
const localeChanged =
changedProperties.has("hass") &&
this.hass &&
changedProperties.get("hass") &&
changedProperties.get("hass").locale.language !==
this.hass.locale.language;
if (
changedProperties.has("languages") ||
changedProperties.has("value") ||
localeChanged
) {
this._select.layoutOptions();
if (this._select.value !== this.value) {
fireEvent(this, "value-changed", { value: this._select.value });
@ -54,12 +65,15 @@ export class HaLanguagePicker extends LitElement {
this.hass.locale,
this.nativeName
);
const selectedItem = languageOptions.find(
const selectedItemIndex = languageOptions.findIndex(
(option) => option.value === this.value
);
if (!selectedItem) {
if (selectedItemIndex === -1) {
this.value = undefined;
}
if (localeChanged) {
this._select.select(selectedItemIndex);
}
}
}