ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

fix(ui5-toolbar-select): display not updating on programmatic option selection

Open NakataCode opened this issue 5 months ago • 1 comments

Problem

Since v2.15.0, changing the selected option programmatically (setting ToolbarSelectOption.selected = true/false) correctly updated the outer ui5-toolbar-select-option elements but left the inner ui5-select display frozen on the initially selected option.

Two root causes:

  1. ToolbarSelectOption had a custom getter reading hasAttribute("selected"). The framework sets the DOM attribute before calling the property setter, so change detection always saw old === new and skipped invalidation — meaning ToolbarSelect never re-rendered on programmatic changes.

  2. The template passed value={this.value} to the inner <Select>, feeding _valueStorage on every render. Once set, Select._applySelectionByValue locks the display to the stored string and ignores the selected attribute on inner options entirely.

Solution

  • ToolbarSelectOption — revert to plain @property, removing the broken getter/setter. Framework change detection now works correctly.
  • ToolbarSelectTemplate — remove value={this.value} from inner <Select>. Selection is driven by selected on inner <Option> elements as rendered by the template.
  • ToolbarSelect:
    • value setter: skip forwarding empty string to avoid poisoning _valueStorage on init.
    • value getter: read directly from the selected option, no _valueStorage dependency.
    • onBeforeRendering: enforce single-selection (last selected wins), guarded to avoid unnecessary writes that could trigger re-render loops.
    • onAfterRendering: deferred apply for explicit value= API only, clears _value after applying.
    • _syncOptions: clear _value on user interaction so a prior explicit value= assignment does not override the user's choice.

Fixes: #12619

NakataCode avatar Jun 26 '26 11:06 NakataCode

🚀 Deployed on https://pr-13751--ui5-webcomponents-preview.netlify.app