Skip to content

Commit 3f275b8

Browse files
authored
fix(ui5-step-input): fix change event firing in some cases (#6511)
1 parent 2576f56 commit 3f275b8

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

packages/main/src/StepInput.ts

+3
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ class StepInput extends UI5Element implements IFormElement {
436436

437437
_onInputFocusIn() {
438438
this._inputFocused = true;
439+
if (this.value !== this._previousValue) {
440+
this._previousValue = this.value;
441+
}
439442
}
440443

441444
_onInputFocusOut() {

packages/main/test/pages/StepInput.html

+25
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ <h3>StepInput with valueState=Error</h3>
135135
></ui5-step-input>
136136
</div>
137137

138+
<div>
139+
<h3>StepInput change event test</h3>
140+
<ui5-step-input id="stepInputChange1"
141+
class="stepinput2auto"
142+
value="1"
143+
min="1"
144+
step="1000"
145+
></ui5-step-input>
146+
<ui5-step-input id="stepInputChange2"
147+
class="stepinput2auto"
148+
value="1000"
149+
min="1"
150+
step="1000"
151+
></ui5-step-input>
152+
</div>
153+
138154
<h3> 'change' event result</h3>
139155
<ui5-input id="changeResult"></ui5-input>
140156

@@ -156,6 +172,15 @@ <h3> 'change' event result</h3>
156172
siCompact.addEventListener('ui5-change', displayChange);
157173
siMinMax.addEventListener('ui5-change', displayChange);
158174
siPrecision.addEventListener('ui5-change', displayChange);
175+
176+
stepInputChange1.addEventListener('ui5-change', function(e) {
177+
const val = Number.parseInt(e.target.value, 10);
178+
stepInputChange2.value = val + 999;
179+
displayChange(e);
180+
});
181+
182+
stepInputChange2.addEventListener('ui5-change', displayChange);
183+
159184
</script>
160185

161186
</body>

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,29 @@ describe("'change' event firing", () => {
433433
assert.strictEqual(await siMinMax.getProperty("value"), 0, "Value is increased correctly to 1");
434434
assert.strictEqual(Number(await changeResult.getProperty("value")), 2, "'change' event is fired 2 times");
435435
});
436+
437+
it("'change' event should be fired after changing value programatically and then manual entry of the previous value and focus out", async () => {
438+
await browser.url(`test/pages/StepInput.html`);
439+
const siChange1 = await browser.$("#stepInputChange1");
440+
const siChange2 = await browser.$("#stepInputChange2");
441+
const incButton = await siChange1.shadow$(".ui5-step-inc");
442+
const initValue1 = await siChange1.getProperty("value");
443+
const initValue2 = await siChange2.getProperty("value");
444+
const changeResult = await browser.$("#changeResult");
445+
446+
await incButton.click();
447+
const newValue1 = await siChange1.getProperty("value");
448+
assert.strictEqual(await siChange1.getProperty("value"), initValue1 + 1000, "Value of the first step input is increased correctly to " + (initValue1 + 1000));
449+
assert.strictEqual(await siChange2.getProperty("value"), newValue1 + 999, "Value of the second step input is increased correctly to " + (newValue1 + 999));
450+
assert.strictEqual(Number(await changeResult.getProperty("value")), 1, "'change' event is fired 1 time");
451+
452+
await siChange2.doubleClick();
453+
await siChange2.keys(initValue2.toString());
454+
await siChange2.keys("Tab");
455+
assert.strictEqual(await siChange2.getProperty("value"), initValue2, "Value of the second step input is set correctly to " + initValue2);
456+
assert.strictEqual(Number(await changeResult.getProperty("value")), 2, "'change' event is fired 2 times");
457+
});
458+
436459
});
437460

438461
describe("Accessibility related parameters", async () => {
@@ -457,4 +480,4 @@ describe("Accessibility related parameters", async () => {
457480
assert.strictEqual(await siInner.getAttribute("aria-label"), "test-aria-label", "'aria-label' attribute exists and has correct value 'test-aria-label'");
458481
});
459482

460-
});
483+
});

0 commit comments

Comments
 (0)