Skip to content

Commit f92593a

Browse files
authored
fix: defaultValue wrongly overrode value (antd#30873) (#335)
1 parent 8482dda commit f92593a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/InputNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const InputNumber = React.forwardRef(
113113
// ============================ Value =============================
114114
// Real value control
115115
const [decimalValue, setDecimalValue] = React.useState<DecimalClass>(() =>
116-
getMiniDecimal(defaultValue ?? value),
116+
getMiniDecimal(value ?? defaultValue),
117117
);
118118

119119
function setUncontrolledDecimalValue(newDecimal: DecimalClass) {

tests/props.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ describe('InputNumber.Props', () => {
282282
expect(wrapper.getInputValue()).toEqual('9');
283283
expect(wrapper.exists('.rc-input-number-out-of-range')).toBeFalsy();
284284
});
285+
286+
it('value can override given defaultValue', () => {
287+
const wrapper = mount(<InputNumber value={2} defaultValue={1} />);
288+
expect(wrapper.getInputValue()).toEqual('2');
289+
});
285290
});
286291

287292
describe(`required prop`, () => {

0 commit comments

Comments
 (0)