Fix behavior of select dropdowns when options change (#24603)

* Fix behavior of select dropdowns when options change

* new approach

* memoize
This commit is contained in:
karwosts
2025-03-17 14:11:37 -07:00
committed by GitHub
parent 5803ab68c2
commit a5b7bb8391
7 changed files with 38 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
import { SelectBase } from "@material/mwc-select/mwc-select-base";
import { mdiMenuDown } from "@mdi/js";
import type { PropertyValues } from "lit";
import { css, html, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@@ -24,6 +25,16 @@ export class HaControlSelectMenu extends SelectBase {
@property({ type: Boolean, attribute: "hide-label" })
public hideLabel = false;
@property() public options;
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (changedProps.get("options")) {
this.layoutOptions();
this.selectByValue(this.value);
}
}
public override render() {
const classes = {
"select-disabled": this.disabled,