Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -899,20 +899,12 @@ describe("calcite-input-number", () => {
expect(Number(await element.getProperty("value"))).toBe(195);
});

it("disallows typing number with shift modifier key down", async () => {
it("disallows typing non-numeric characters with shift modifier key down", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-input-number></calcite-input-number>`);
const calciteInput = await page.find("calcite-input-number");
const input = await page.find("calcite-input-number >>> input");
await calciteInput.callMethod("setFocus");

for (let i = 0; i < numberKeys.length; i++) {
await page.keyboard.down("Shift");
await page.keyboard.press(numberKeys[i] as KeyInput);
await page.keyboard.up("Shift");
expect(await calciteInput.getProperty("value")).toBeFalsy();
expect(await input.getProperty("value")).toBeFalsy();
}
const nonELetterKeys = letterKeys.filter((key) => key !== "e");
for (let i = 0; i < nonELetterKeys.length; i++) {
await page.keyboard.down("Shift");
Expand All @@ -923,6 +915,25 @@ describe("calcite-input-number", () => {
}
});

it("allows typing numeric characters with shift modifier key down (#6854)", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-input type="number"></calcite-input>`);
const calciteInput = await page.find("calcite-input");
const input = await page.find("calcite-input >>> input");
await calciteInput.callMethod("setFocus");
const numberKeysExcludingZero = numberKeys.slice(1);

let result = "";
for (let i = 0; i < numberKeysExcludingZero.length; i++) {
await page.keyboard.down("Shift");
await page.keyboard.press(numberKeysExcludingZero[i] as KeyInput);
result += numberKeysExcludingZero[i];
await page.keyboard.up("Shift");
expect(await calciteInput.getProperty("value")).toBe(result);
expect(await input.getProperty("value")).toBe(result);
}
});

it("allows shift tabbing", async () => {
const page = await newE2EPage();
await page.setContent(html`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ export class InputNumber
return;
}
const isShiftTabEvent = event.shiftKey && event.key === "Tab";
if (supportedKeys.includes(event.key) && (!event.shiftKey || isShiftTabEvent)) {
if (supportedKeys.includes(event.key) || isShiftTabEvent) {
if (event.key === "Enter") {
this.emitChangeIfUserModified();
}
Expand Down
29 changes: 20 additions & 9 deletions packages/calcite-components/src/components/input/input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,20 +1055,12 @@ describe("calcite-input", () => {
expect(Number(await element.getProperty("value"))).toBe(195);
});

it("disallows typing any letter or number with shift modifier key down", async () => {
it("disallows typing any non-numeric characters with shift modifier key down", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-input type="number"></calcite-input>`);
const calciteInput = await page.find("calcite-input");
const input = await page.find("calcite-input >>> input");
await calciteInput.callMethod("setFocus");

for (let i = 0; i < numberKeys.length; i++) {
await page.keyboard.down("Shift");
await page.keyboard.press(numberKeys[i] as KeyInput);
await page.keyboard.up("Shift");
expect(await calciteInput.getProperty("value")).toBeFalsy();
expect(await input.getProperty("value")).toBeFalsy();
}
const nonELetterKeys = letterKeys.filter((key) => key !== "e");
for (let i = 0; i < nonELetterKeys.length; i++) {
await page.keyboard.down("Shift");
Expand All @@ -1079,6 +1071,25 @@ describe("calcite-input", () => {
}
});

it("allows typing numeric characters with shift modifier key down (#6854)", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-input type="number"></calcite-input>`);
const calciteInput = await page.find("calcite-input");
const input = await page.find("calcite-input >>> input");
await calciteInput.callMethod("setFocus");
const numberKeysExcludingZero = numberKeys.slice(1);

let result = "";
for (let i = 0; i < numberKeysExcludingZero.length; i++) {
await page.keyboard.down("Shift");
await page.keyboard.press(numberKeysExcludingZero[i] as KeyInput);
result += numberKeysExcludingZero[i];
await page.keyboard.up("Shift");
expect(await calciteInput.getProperty("value")).toBe(result);
expect(await input.getProperty("value")).toBe(result);
}
});

it("allows shift tabbing", async () => {
const page = await newE2EPage();
await page.setContent(html`
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ export class Input
return;
}
const isShiftTabEvent = event.shiftKey && event.key === "Tab";
if (supportedKeys.includes(event.key) && (!event.shiftKey || isShiftTabEvent)) {
if (supportedKeys.includes(event.key) || isShiftTabEvent) {
if (event.key === "Enter") {
this.emitChangeIfUserModified();
}
Expand Down