Skip to content

Commit 3f1c267

Browse files
authored
fix(ui5-input): Fix value reset on ESC (#3886)
Now the component is synced with the desired by specifications behavior. If the suggestions popover is opened: ESC closes it. If the suggestions are not opened: ESC resets the value to the last confirmed by the user with 'ENTER' or if there isn't one - with the initial value of the component when focused by the user. Fixes #3784 Closes #3784
1 parent ae74add commit 3f1c267

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/main/src/Input.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ class Input extends UI5Element {
518518
// The value that should be highlited.
519519
this.highlightValue = "";
520520

521+
// The last value confirmed by the user with "ENTER"
522+
this.lastConfirmedValue = "";
523+
521524
// Indicates, if the user pressed the BACKSPACE key.
522525
this._backspaceKeyDown = false;
523526

@@ -656,6 +659,7 @@ class Input extends UI5Element {
656659
const itemPressed = !!(this.Suggestions && this.Suggestions.onEnter(event));
657660
if (!itemPressed) {
658661
this.fireEventByAction(this.ACTION_ENTER);
662+
this.lastConfirmedValue = this.value;
659663
}
660664
}
661665

@@ -667,6 +671,10 @@ class Input extends UI5Element {
667671
// Mark that the selection has been canceled, so the popover can close
668672
// and not reopen, due to receiving focus.
669673
this.suggestionSelectionCanceled = true;
674+
} else if (this.Suggestions && this.Suggestions.isOpened()) {
675+
this.closePopover();
676+
} else {
677+
this.value = this.lastConfirmedValue ? this.lastConfirmedValue : this.previousValue;
670678
}
671679
}
672680

@@ -700,6 +708,7 @@ class Input extends UI5Element {
700708
this.closePopover();
701709

702710
this.previousValue = "";
711+
this.lastConfirmedValue = "";
703712
this.focused = false; // invalidating property
704713
}
705714

@@ -883,6 +892,7 @@ class Input extends UI5Element {
883892
if (fireInput) {
884893
this.value = itemText;
885894
this.valueBeforeItemSelection = itemText;
895+
this.lastConfirmedValue = itemText;
886896
this.fireEvent(this.EVENT_INPUT);
887897
this.fireEvent(this.EVENT_CHANGE);
888898

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,33 @@ describe("Input general interaction", () => {
325325
"The value is restored as ESC has been pressed.");
326326
});
327327

328+
it("input value should be cleared with ESC", () => {
329+
browser.url(`http://localhost:${PORT}/test-resources/pages/Input.html`);
330+
331+
const suggestionsInput = $("#myInputEsc").shadow$("input");
332+
333+
suggestionsInput.click();
334+
suggestionsInput.keys("Some value");
335+
336+
// Close sugggestions
337+
suggestionsInput.keys("Escape");
338+
// Clear value
339+
suggestionsInput.keys("Escape");
340+
341+
assert.strictEqual(suggestionsInput.getValue(), "", "The value is restored as ESC has been pressed.");
342+
343+
suggestionsInput.keys("Some value");
344+
suggestionsInput.keys("Enter");
345+
suggestionsInput.keys("Another value");
346+
347+
// Close sugggestions
348+
suggestionsInput.keys("Escape");
349+
// Clear value
350+
suggestionsInput.keys("Escape");
351+
352+
assert.strictEqual(suggestionsInput.getValue(), "Some value", "The value is restored to the last confirmed by 'ENTER' press one.");
353+
});
354+
328355
it("handles group suggestion item via keyboard", () => {
329356
const suggestionsInput = $("#myInputGrouping").shadow$("input");
330357
const inputResult = $("#inputResultGrouping").shadow$("input");

0 commit comments

Comments
 (0)