From 9323b2f3c05aff95be8f738f1617789ed1af5f09 Mon Sep 17 00:00:00 2001 From: jameslahm <1366463855@qq.com> Date: Wed, 7 Apr 2021 20:30:42 +0800 Subject: [PATCH 1/2] fix: check mergePrecision should consider zero --- src/InputNumber.tsx | 2 +- tests/decimal.test.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index b8524c82..71e7dbd9 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -285,7 +285,7 @@ const InputNumber = React.forwardRef( if (!readOnly && !disabled) { const numStr = updateValue.toString(); const mergedPrecision = getPrecision(numStr, userTyping); - if (mergedPrecision) { + if (mergedPrecision>=0) { updateValue = getMiniDecimal(toFixed(numStr, '.', mergedPrecision)); } diff --git a/tests/decimal.test.tsx b/tests/decimal.test.tsx index 345a6123..651c7b29 100644 --- a/tests/decimal.test.tsx +++ b/tests/decimal.test.tsx @@ -115,6 +115,16 @@ describe('InputNumber.Decimal', () => { expect(wrapper.getInputValue()).toEqual('1.00'); }); + it('zero precision should work',()=>{ + const onChange = jest.fn(); + const wrapper = mount(); + + wrapper.changeValue('1.44'); + wrapper.blurInput(); + expect(onChange).toHaveBeenCalledWith(1); + expect(wrapper.getInputValue()).toEqual('1'); + }) + it('should not trigger onChange when blur InputNumber with precision', () => { const onChange = jest.fn(); const wrapper = mount(); From 59bece58f9a43f8f152f58215bbdb03aff73b467 Mon Sep 17 00:00:00 2001 From: wangao Date: Thu, 8 Apr 2021 16:19:11 +0800 Subject: [PATCH 2/2] style: lint Co-authored-by: afc163 --- src/InputNumber.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index 71e7dbd9..e23a74f2 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -285,7 +285,7 @@ const InputNumber = React.forwardRef( if (!readOnly && !disabled) { const numStr = updateValue.toString(); const mergedPrecision = getPrecision(numStr, userTyping); - if (mergedPrecision>=0) { + if (mergedPrecision >= 0) { updateValue = getMiniDecimal(toFixed(numStr, '.', mergedPrecision)); }