Skip to content

Commit 19886f2

Browse files
committed
fix(ui5-combobox): allow setting value programmatically
The Input's text value is now updated immediately once changing it programmatically (via JavaScript, not by user interaction). Fixes: SAP#2233
1 parent 028ef3c commit 19886f2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/main/src/ComboBox.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class ComboBox extends UI5Element {
391391
onBeforeRendering() {
392392
let domValue;
393393

394-
if (this._initialRendering) {
394+
if (this._initialRendering || !this._isValueChangedByInteraction()) {
395395
domValue = this.value;
396396
this._filteredItems = this.items;
397397
} else {
@@ -443,6 +443,12 @@ class ComboBox extends UI5Element {
443443

444444
this.toggleValueStatePopover(this.shouldOpenValueStateMessagePopover);
445445
this.storeResponsivePopoverWidth();
446+
447+
// Reset the interaction flag only after any scheduled re-renderings called in this method are done,
448+
// avoid resetting the indicator before the calculations caused by the the user action are finished
449+
setTimeout(() => {
450+
this._setValueChangedByInteraction(false);
451+
});
446452
}
447453

448454
shouldClosePopover() {
@@ -608,6 +614,7 @@ class ComboBox extends UI5Element {
608614
_keydown(event) {
609615
const isArrowKey = isDown(event) || isUp(event);
610616
this._autocomplete = !(isBackSpace(event) || isDelete(event));
617+
this._setValueChangedByInteraction(true);
611618

612619
if (isArrowKey) {
613620
this.handleArrowKeyPress(event);
@@ -709,6 +716,7 @@ class ComboBox extends UI5Element {
709716
return item;
710717
});
711718

719+
this._setValueChangedByInteraction(true);
712720
this._inputChange();
713721
this._closeRespPopover();
714722
}
@@ -717,6 +725,14 @@ class ComboBox extends UI5Element {
717725
this._itemFocused = true;
718726
}
719727

728+
_isValueChangedByInteraction() {
729+
return this._isChangedByInteraction;
730+
}
731+
732+
_setValueChangedByInteraction(isValueChangedByInteraction) {
733+
this._isChangedByInteraction = isValueChangedByInteraction;
734+
}
735+
720736
get _headerTitleText() {
721737
return this.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
722738
}

packages/main/test/specs/ComboBox.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,14 @@ describe("General interaction", () => {
325325

326326
arrow.click();
327327
assert.strictEqual(listItem.shadow$(".ui5-li-info").getText(), "DZ", "Additional item text should be displayed");
328+
});
329+
330+
it ("Tests setValue() update programatically (via JS, not by user interaction)", () => {
331+
const combo = $("#combo2");
332+
const input = combo.shadow$("#ui5-combobox-input");
333+
334+
combo.setProperty("value", "Value is set instantly");
335+
336+
assert.strictEqual(input.getAttribute("value"), "Value is set instantly", "Value is updated in realtime when set with direct property update");
328337
});
329338
});

0 commit comments

Comments
 (0)