Skip to content

Commit f858fd8

Browse files
ilhan007vladitasev
authored andcommitted
refactor(ui5-input): Add hook for value update on preview (#1956)
Added extension point to allow extending components control the behaviour on suggestion preview. The default behaviour of the Input with suggestions is to replace the current value with the value of the previewed suggestion, when the user navigates with UP/DOWN arrows. But, there are use cases as in the attached issue, that instead of replacing the entire text, just part of it has to be replaced, changed or added to. FIXES: #1878
1 parent e8236c6 commit f858fd8

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/main/src/Input.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ class Input extends UI5Element {
694694
}
695695

696696
_afterClosePopover() {
697-
this._announceSelectedItem();
697+
this.announceSelectedItem();
698698

699699
// close device's keyboard and prevent further typing
700700
if (isPhone()) {
@@ -780,18 +780,22 @@ class Input extends UI5Element {
780780
}
781781

782782
previewSuggestion(item) {
783-
this.valueBeforeItemSelection = this.value;
783+
const emptyValue = item.type === "Inactive" || item.group;
784784

785-
if (item.type === "Inactive" || item.group) {
786-
this.value = "";
787-
} else {
788-
this.value = item.textContent;
789-
}
790-
791-
this._announceSelectedItem();
785+
this.valueBeforeItemSelection = this.value;
786+
this.updateValueOnPreview(emptyValue ? "" : item.textContent);
787+
this.announceSelectedItem();
792788
this._previewItem = item;
793789
}
794790

791+
/**
792+
* Updates the input value on item preview.
793+
* @param {itemValue} itemValue The value of the item that is on preview
794+
*/
795+
updateValueOnPreview(itemValue) {
796+
this.value = itemValue;
797+
}
798+
795799
/**
796800
* The suggestion item on preview.
797801
* @type { ui5-suggestion-item }
@@ -936,7 +940,7 @@ class Input extends UI5Element {
936940
};
937941
}
938942

939-
_announceSelectedItem() {
943+
announceSelectedItem() {
940944
const invisibleText = this.shadowRoot.querySelector(`#${this._id}-selectionText`);
941945

942946
if (this.Suggestions && this.Suggestions._isItemOnTarget()) {

0 commit comments

Comments
 (0)