Skip to content

Commit 7db6786

Browse files
authored
fix(number-input): toFormValue should handle both undefined and null (#870)
1 parent e85da58 commit 7db6786

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/inputs/number-input/number-input.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ NumberInput.defaultProps = {
6060
horizontalConstraint: 'scale',
6161
};
6262

63-
NumberInput.toFormValue = numberOrString =>
64-
typeof numberOrString === 'undefined' ? '' : numberOrString;
63+
NumberInput.toFormValue = numberOrString => {
64+
if (
65+
typeof numberOrString === 'number' ||
66+
typeof numberOrString === 'string'
67+
) {
68+
return numberOrString;
69+
}
70+
return '';
71+
};
6572

6673
NumberInput.isEmpty = value => {
6774
if (typeof value === 'string') return value.trim().length === 0;

src/components/inputs/number-input/number-input.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ describe('NumberInput.toFormValue', () => {
1616
expect(NumberInput.toFormValue('3,4')).toEqual('3,4');
1717
});
1818
});
19-
describe('when called with undefined', () => {
19+
describe('when called with undefined or null', () => {
2020
it('should return an empty string', () => {
2121
expect(NumberInput.toFormValue()).toEqual('');
2222
expect(NumberInput.toFormValue(undefined)).toEqual('');
23+
expect(NumberInput.toFormValue(null)).toEqual('');
2324
});
2425
});
2526
});

0 commit comments

Comments
 (0)