From d7ae50843afc190ad1b38ffb257cd8af617f802d Mon Sep 17 00:00:00 2001 From: neotan Date: Sat, 5 Jun 2021 21:16:34 +0800 Subject: [PATCH] fix: defaultValue wrongly overrode value (antd#30873) --- src/InputNumber.tsx | 2 +- tests/props.test.tsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index 5a16cc01..1d9f019f 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -113,7 +113,7 @@ const InputNumber = React.forwardRef( // ============================ Value ============================= // Real value control const [decimalValue, setDecimalValue] = React.useState(() => - getMiniDecimal(defaultValue ?? value), + getMiniDecimal(value ?? defaultValue), ); function setUncontrolledDecimalValue(newDecimal: DecimalClass) { diff --git a/tests/props.test.tsx b/tests/props.test.tsx index 70358d57..1bce1c2f 100644 --- a/tests/props.test.tsx +++ b/tests/props.test.tsx @@ -282,6 +282,11 @@ describe('InputNumber.Props', () => { expect(wrapper.getInputValue()).toEqual('9'); expect(wrapper.exists('.rc-input-number-out-of-range')).toBeFalsy(); }); + + it('value can override given defaultValue', () => { + const wrapper = mount(); + expect(wrapper.getInputValue()).toEqual('2'); + }); }); describe(`required prop`, () => {