Skip to content

Commit

Permalink
- should try to correct the value if old formatted value is provided …
Browse files Browse the repository at this point in the history
…but the format prop changes
  • Loading branch information
s-yadav committed May 15, 2023
1 parent 9988c82 commit 49a0003
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-number-format",
"description": "React component to format number in an input or as a text.",
"version": "5.2.0",
"version": "5.2.1",
"main": "dist/react-number-format.cjs.js",
"module": "dist/react-number-format.es.js",
"types": "types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function useInternalValues(
formattedValue = format(numAsString);
} else {
numAsString = removeFormatting(value, undefined);
formattedValue = value;
formattedValue = format(numAsString);
}

return { formattedValue, numAsString };
Expand Down
10 changes: 10 additions & 0 deletions test/library/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ describe('NumberFormat as input', () => {
expect(value.innerText).toEqual('1123234512');
});

it('should try to correct the value if old formatted value is provided but the format prop changes', async () => {
const { input, rerender } = await render(
<NumericFormat value="$1,234" prefix="$" thousandSeparator />,
);
expect(input.value).toEqual('$1,234');

await rerender(<NumericFormat value="$1,234" prefix="Rs. " thousandSeparator />);
expect(input.value).toEqual('Rs. 1,234');
});

describe('Test masking', () => {
it('should allow mask as string', () => {
const wrapper = mount(<PatternFormat format="#### #### ####" mask="_" />);
Expand Down

0 comments on commit 49a0003

Please sign in to comment.