Skip to content
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

[core] fix(NumericInput): increment/decrement with very small step size #6382

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/core/src/components/forms/numericInputUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getDecimalSeparator(locale: string) {
}

export function toLocaleString(num: number, locale: string = "en-US") {
return sanitizeNumericInput(num.toLocaleString(locale), locale);
return sanitizeNumericInput(num.toLocaleString(locale, { roundingPriority: "morePrecision" } as any), locale);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used as any here because this property has not included in the type, I was wondering if we have a better way to do it?

Reference: microsoft/TypeScript#52072

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rafael-Martins why do you need to cast as any? I'd prefer to avoid that cast if we can. If it's absolutely necessary, then it should be accompanied with a // HACKHACK: explanation comment on the previous line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry, I forgot to send my commentary about it, but the reason is:

I used as any here because this property has not included in the type, I was wondering if we have a better way to do it?

Reference: microsoft/TypeScript#52072

I will add the HACKHACK or even try a better approach!

}

export function clampValue(value: number, min?: number, max?: number) {
Expand Down
17 changes: 17 additions & 0 deletions packages/core/test/controls/numericInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,23 @@ describe("<NumericInput>", () => {
expect(component.find("input").prop("value")).to.equal("1.001");
});

it("handle big decimal numbers", () => {
const onValueChangeSpy = spy();
const component = mount(
<NumericInput
onValueChange={onValueChangeSpy}
value={0}
stepSize={0.000000000000000001}
minorStepSize={0.000000000000000001}
/>,
);
const input = component.find("input");

console.log(input.simulate("keydown", { key: "ArrowUp" }));

assert.isTrue(onValueChangeSpy.calledWith(0.000000000000000001));
});

it("changes max precision appropriately when the min/max stepSize props change", () => {
const onValueChangeSpy = spy();
const component = mount(
Expand Down