From a5f27f21cb359f60dc2ffdc7c74b2cb3a39615e9 Mon Sep 17 00:00:00 2001 From: Tsanislav Gatev Date: Thu, 1 Jul 2021 11:11:34 +0300 Subject: [PATCH] fix(ui5-step-input): firing step input once when value is deleted (#3474) fixes: #3457 --- packages/main/src/StepInput.js | 9 +++++++-- packages/main/test/specs/StepInput.spec.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/main/src/StepInput.js b/packages/main/src/StepInput.js index 5376527e4a51..351c71cb0dc1 100644 --- a/packages/main/src/StepInput.js +++ b/packages/main/src/StepInput.js @@ -502,8 +502,10 @@ class StepInput extends UI5Element { } _fireChangeEvent() { - this._previousValue = this.value; - this.fireEvent("change", { value: this.value }); + if (this._previousValue !== this.value) { + this._previousValue = this.value; + this.fireEvent("change", { value: this.value }); + } } /** @@ -553,6 +555,9 @@ class StepInput extends UI5Element { } _onInputChange(event) { + if (this.input.value === "") { + this.input.value = this.min || 0; + } const inputValue = this._preciseValue(parseFloat(this.input.value)); if (this.value !== this._previousValue || this.value !== inputValue) { this.value = inputValue; diff --git a/packages/main/test/specs/StepInput.spec.js b/packages/main/test/specs/StepInput.spec.js index 74f3d0d08fb5..6e2d57419f3f 100644 --- a/packages/main/test/specs/StepInput.spec.js +++ b/packages/main/test/specs/StepInput.spec.js @@ -424,6 +424,25 @@ describe("'change' event firing", () => { assert.strictEqual(Number(changeResult.getProperty("value")), 2, "'change' event is fired 2 times"); }); + it("'change' event should be fired once after element deleted and focus out", () => { + browser.url(`http://localhost:${PORT}/test-resources/pages/StepInput.html`); + const siCozy = $("#stepInputCozy"); + const siMinMax = $("#stepInputMinMax"); + const changeResult = $("#changeResult"); + + siMinMax.click(); + siMinMax.keys("ArrowUp"); + siMinMax.keys("ArrowUp"); + siMinMax.keys("ArrowUp"); + siCozy.click(); + assert.strictEqual(siMinMax.getProperty("value"), 3, "Value is increased correctly to 3"); + assert.strictEqual(Number(changeResult.getProperty("value")), 1, "'change' event is fired 1 time"); + siMinMax.doubleClick(); + siMinMax.keys("Backspace"); + siCozy.click(); + assert.strictEqual(siMinMax.getProperty("value"), 0, "Value is increased correctly to 1"); + assert.strictEqual(Number(changeResult.getProperty("value")), 2, "'change' event is fired 2 times"); + }); }); describe("Accessibility related parameters", () => {