-
Notifications
You must be signed in to change notification settings - Fork 89
fix(input, input-number): no longer removes trailing decimal separator #7159
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
Changes from all commits
59b5a85
4613212
f241c17
387db5b
54b7143
5d6f507
c6a1e71
cffe278
1c60d07
eacde2d
c447239
7a0480a
87f15d7
63dff04
d06003b
6751aaa
688b98a
f7b9f94
43b3075
cd4a3ac
98c86d4
ce04bab
ecbc697
fbc3831
de31f7c
05b771c
c507400
4a57130
dfc9311
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1055,6 +1055,35 @@ describe("calcite-input", () => { | |
| expect(Number(await element.getProperty("value"))).toBe(195); | ||
| }); | ||
|
|
||
| it("allows deleting exponentail number from decimal and adding trailing zeros", 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"); | ||
| await page.waitForChanges(); | ||
| await typeNumberValue(page, "2.100e10"); | ||
| await page.waitForChanges(); | ||
| expect(await calciteInput.getProperty("value")).toBe("2.1e10"); | ||
| expect(await input.getProperty("value")).toBe("2.1e10"); | ||
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await page.waitForChanges(); | ||
| expect(await calciteInput.getProperty("value")).toBe("2.1e1"); | ||
| expect(await input.getProperty("value")).toBe("2.1e1"); | ||
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await page.waitForChanges(); | ||
| expect(await calciteInput.getProperty("value")).toBe("2.1"); | ||
| expect(await input.getProperty("value")).toBe("2.1"); | ||
|
|
||
| await page.keyboard.type("000"); | ||
| await page.waitForChanges(); | ||
| expect(await calciteInput.getProperty("value")).toBe("2.1000"); | ||
| expect(await input.getProperty("value")).toBe("2.1000"); | ||
| }); | ||
|
|
||
| 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>`); | ||
|
|
@@ -1291,6 +1320,80 @@ describe("calcite-input", () => { | |
| expect(await calciteInput.getProperty("value")).toBe(assertedValue); | ||
| expect(await internalLocaleInput.getProperty("value")).toBe(localizedValue); | ||
| }); | ||
|
|
||
| it(`should be able to append values after Backspace for ${locale} locale`, async () => { | ||
| const page = await newE2EPage(); | ||
| await page.setContent(` | ||
| <calcite-input lang="${locale}" type="number"></calcite-input> | ||
| `); | ||
|
|
||
| numberStringFormatter.numberFormatOptions = { | ||
| locale, | ||
| numberingSystem: "latn", | ||
| useGrouping: false | ||
| }; | ||
| const decimalSeparator = numberStringFormatter.decimal; | ||
| const calciteInput = await page.find("calcite-input"); | ||
| const input = await page.find("calcite-input >>> input"); | ||
| await calciteInput.callMethod("setFocus"); | ||
| await typeNumberValue(page, `0${decimalSeparator}0000`); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}0000`); | ||
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await typeNumberValue(page, "1"); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}0001`); | ||
|
|
||
| await typeNumberValue(page, "01"); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}000101`); | ||
| }); | ||
|
|
||
| it(`should keep leading decimal separator while input is focused on Backspace ${locale} locale `, async () => { | ||
| const page = await newE2EPage(); | ||
| await page.setContent(` | ||
| <calcite-input lang="${locale}" type="number"></calcite-input> | ||
| `); | ||
|
|
||
| numberStringFormatter.numberFormatOptions = { | ||
| locale, | ||
| numberingSystem: "latn", | ||
| useGrouping: false | ||
| }; | ||
| const decimalSeparator = numberStringFormatter.decimal; | ||
| const calciteInput = await page.find("calcite-input"); | ||
| const input = await page.find("calcite-input >>> input"); | ||
| await calciteInput.callMethod("setFocus"); | ||
| await typeNumberValue(page, `0${decimalSeparator}01`); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}01`); | ||
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}0`); | ||
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}`); | ||
|
|
||
| await typeNumberValue(page, "01"); | ||
| await page.waitForChanges(); | ||
| expect(await input.getProperty("value")).toBe(`0${decimalSeparator}01`); | ||
| }); | ||
|
|
||
| it(`should sanitize leading decimal zeros on initial render ${locale} locale`, async () => { | ||
| const page = await newE2EPage(); | ||
| await page.setContent(html`<calcite-input value="0.0000" lang="${locale}" type="number"></calcite-input>`); | ||
|
|
||
| numberStringFormatter.numberFormatOptions = { | ||
| locale, | ||
| numberingSystem: "latn", | ||
| useGrouping: false | ||
| }; | ||
| const input = await page.find("calcite-input >>> input"); | ||
| expect(await input.getProperty("value")).toBe("0"); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an e2e test (doesn't have to be for every locale) for this number and then type three backspaces:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For context,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -1551,7 +1654,7 @@ describe("calcite-input", () => { | |
|
|
||
| await page.keyboard.press("Backspace"); | ||
| await page.waitForChanges(); | ||
| expect(await element.getProperty("value")).toBe("1"); | ||
| expect(await element.getProperty("value")).toBe("1."); | ||
| expect(calciteInputInput).toHaveReceivedEventTimes(1); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
.should benumberFormatter.decimalhere, since it is being done before delocalizationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think so, if you see that
setNumberValueparses delocalized value ininputNumberInputHandler. The only instance when we try to check if there is a trailingDecimalSeparator is when the value is deleted which invokesinputNumberInputHandlermethod.