Skip to content

fix(ui5-step-input): firing step input once when value is deleted #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/main/src/StepInput.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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