Skip to content

Commit 7b60885

Browse files
authoredMay 19, 2021
fix(ui5-textarea): revert value on escape (#3261)
* fix(ui5-textarea): revert value on escape * change test name * fire input event * rename variable
1 parent 0c7e58b commit 7b60885

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

‎packages/main/src/TextArea.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/Ari
66
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
77
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
88
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
9+
import { isEscape } from "@ui5/webcomponents-base/dist/Keys.js";
910
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
1011
import Popover from "./Popover.js";
1112

@@ -427,8 +428,16 @@ class TextArea extends UI5Element {
427428
return this.getDomRef().querySelector("textarea");
428429
}
429430

430-
_onkeydown() {
431+
_onkeydown(event) {
431432
this._keyDown = true;
433+
434+
if (isEscape(event)) {
435+
const nativeTextArea = this.getInputDomRef();
436+
437+
this.value = this.previousValue;
438+
nativeTextArea.value = this.value;
439+
this.fireEvent("input");
440+
}
432441
}
433442

434443
_onkeyup() {
@@ -438,6 +447,7 @@ class TextArea extends UI5Element {
438447
_onfocusin() {
439448
this.focused = true;
440449
this._openValueStateMsgPopover = true;
450+
this.previousValue = this.getInputDomRef().value;
441451
}
442452

443453
_onfocusout() {

‎packages/main/test/specs/TextArea.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,27 @@ describe("when enabled", () => {
225225
});
226226
});
227227
});
228+
229+
describe("Value update", () => {
230+
before(() => {
231+
browser.url(`http://localhost:${PORT}/test-resources/pages/TextArea.html`);
232+
});
233+
234+
it("Should revert the DOM value, when escape is pressed", () => {
235+
const textarea = $("#basic-textarea");
236+
237+
// act
238+
textarea.click();
239+
textarea.keys("1");
240+
textarea.keys("2");
241+
242+
// assert
243+
assert.strictEqual(textarea.getProperty("value"), "12", "Value is updated");
244+
245+
// act
246+
textarea.keys("Escape");
247+
248+
// assert
249+
assert.strictEqual(textarea.getProperty("value"), "", "Value is reverted");
250+
});
251+
});

0 commit comments

Comments
 (0)
Please sign in to comment.