Skip to content

Commit

Permalink
fix(Input): handle forever zero
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Nov 9, 2018
1 parent 1eb2043 commit fc647ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/atoms/dataEntry/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Input extends PureComponent<InputProps> {

if (value.toString().length <= maxLength || hasNotMaxLength) {
if (type === 'number') {
onChange && onChange(Number(value) || null, event);
onChange && onChange(!value ? value : Number(value), event);
}
else {
onChange && onChange(value, event);
Expand Down
7 changes: 2 additions & 5 deletions src/atoms/dataEntry/Input/Input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ describe('<Input />', () => {
const onChange = jest.fn();
const wrapper = mount(<Input onChange={ onChange } type="number" />);

wrapper.find('input').simulate('change', { target: { value: 'val' }});
expect(onChange.mock.calls[0][0]).toBe(null);

wrapper.find('input').simulate('change', { target: { value: '42' }});
expect(onChange.mock.calls[1][0]).toBe(42);
expect(typeof onChange.mock.calls[1][0]).toBe('number');
expect(onChange.mock.calls[0][0]).toBe(42);
expect(typeof onChange.mock.calls[0][0]).toBe('number');
});

it('should not call onCahnge with max value', () => {
Expand Down

0 comments on commit fc647ae

Please sign in to comment.