Skip to content

Commit

Permalink
refactor: update "value" setter (#8067)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ilhan007 authored and PetyaMarkovaBogdanova committed Jan 17, 2024
1 parent 758967c commit c2616d8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/main/src/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<IOption>;

selectOptions.forEach(option => {
option.selected = !!((option.getAttribute("value") || option.textContent) === newValue);
});
}

Expand Down

0 comments on commit c2616d8

Please sign in to comment.