Skip to content

Commit

Permalink
fix(input-number): prevents mutating value on blur (#8226)
Browse files Browse the repository at this point in the history
**Related Issue:** #7188 

## Summary

Prevents increasing/decreasing the value in `calcite-input-number` on
`blur` via keyboard or mouse
  • Loading branch information
anveshmekala authored and benelan committed Nov 24, 2023
1 parent 91fc52f commit 55a174e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1748,4 +1748,28 @@ describe("calcite-input-number", () => {
await page.waitForChanges();
expect(await inputNumber.getProperty("value")).toEqual(value);
});

it("should not change the value when user Tab out of the input with ArrowUp/ArrowDown keys are down", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-input-number value="0"></calcite-input-number>`);
const calciteInputNumberInput = await page.spyOnEvent("calciteInputNumberInput");
const input = await page.find("calcite-input-number");
expect(calciteInputNumberInput).toHaveReceivedEventTimes(0);

await page.keyboard.press("Tab");
await page.waitForChanges();
await page.keyboard.down("ArrowUp");
// timeout is used to simulate long press.
await page.waitForTimeout(3000);
await page.keyboard.press("Tab");
await page.waitForChanges();

const totalNudgesUp = calciteInputNumberInput.length;
expect(await input.getProperty("value")).toBe(`${totalNudgesUp}`);
expect(calciteInputNumberInput).toHaveReceivedEventTimes(totalNudgesUp);

await page.waitForTimeout(3000);
expect(await input.getProperty("value")).toBe(`${totalNudgesUp}`);
expect(calciteInputNumberInput).toHaveReceivedEventTimes(totalNudgesUp);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export class InputNumber
};

private inputNumberBlurHandler = () => {
window.clearInterval(this.nudgeNumberValueIntervalId);
this.calciteInternalInputNumberBlur.emit();
this.emitChangeIfUserModified();
};
Expand Down

0 comments on commit 55a174e

Please sign in to comment.