Skip to content

Commit

Permalink
fix(ui5-step-input): firing step input once when value is deleted (#3474
Browse files Browse the repository at this point in the history
)

fixes: #3457
  • Loading branch information
tsanislavgatev committed Jul 1, 2021
1 parent 2f67084 commit a5f27f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/main/src/StepInput.js
Expand Up @@ -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 });
}
}

/**
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions packages/main/test/specs/StepInput.spec.js
Expand Up @@ -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", () => {
Expand Down

0 comments on commit a5f27f2

Please sign in to comment.