Skip to content

Commit

Permalink
[core] fix(NumericInput): increment/decrement w/ small step size (#6382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael-Martins authored Sep 22, 2023
1 parent 519e9ae commit e15084f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/components/forms/numericInputUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function getDecimalSeparator(locale: string) {
}

export function toLocaleString(num: number, locale: string = "en-US") {
return sanitizeNumericInput(num.toLocaleString(locale), locale);
// HACKHACK: roundingPriority is not supported yet in TypeScript https://github.com/microsoft/TypeScript/issues/43336
return sanitizeNumericInput(num.toLocaleString(locale, { roundingPriority: "morePrecision" } as any), locale);
}

export function clampValue(value: number, min?: number, max?: number) {
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/controls/numericInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,21 @@ 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");
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

1 comment on commit e15084f

@adidahiya
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.