From c2616d87fe312e60f261546dd1cf4b296a9333d8 Mon Sep 17 00:00:00 2001 From: ilhan orhan Date: Tue, 9 Jan 2024 15:28:28 +0200 Subject: [PATCH] refactor: update "value" setter (#8067) There are use-cases when the "value" setter is called early on, before the component definition and that call simply does not occur and the state is lost. - make "value" setter "upgraded" (as it's done for the @property decorated properties), so that the setter is available - the setter no longer rely on the component framework-created accessors (this.options or option.disabled) because web components might not be defined yet. Instead, rely on the Light DOM - children and attributes. --- packages/main/src/Select.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/main/src/Select.ts b/packages/main/src/Select.ts index 2c760c8158b0..defd6fd54eaa 100644 --- a/packages/main/src/Select.ts +++ b/packages/main/src/Select.ts @@ -467,6 +467,8 @@ class Select extends UI5Element implements IFormElement { this._onMenuChange = this.onMenuChange.bind(this); this._attachMenuListeners = this.attachMenuListeners.bind(this); this._detachMenuListeners = this.detachMenuListeners.bind(this); + + this._upgradeProperty("value"); } onBeforeRendering() { @@ -540,8 +542,11 @@ class Select extends UI5Element implements IFormElement { * @formEvents change liveChange */ set value(newValue: string) { - this.selectOptions.forEach(option => { - option.selected = !!((option.value || option.textContent) === newValue); + const menu = this._getSelectMenu(); + const selectOptions = Array.from(menu ? menu.children : this.children).filter(option => !option.getAttribute("disabled")) as Array; + + selectOptions.forEach(option => { + option.selected = !!((option.getAttribute("value") || option.textContent) === newValue); }); }