Skip to content

Commit

Permalink
fix(Input): bug of value=0 with htmlType=number
Browse files Browse the repository at this point in the history
  • Loading branch information
潕量 committed Nov 23, 2018
1 parent 5d5a497 commit 0805a38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/input/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class Base extends React.Component {
});
}

if (this.props.htmlType === 'number') {
// Number('') = 0
if (value && this.props.htmlType === 'number') {
value = Number(value);
}

Expand Down
14 changes: 10 additions & 4 deletions test/input/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,33 @@ describe('input', () => {
return (
<Input ref='input' onFocus={(e) => {
assert(this.refs.input.getInstance().getInputNode() !== undefined)
done();
}}/>
);
}
}
let wrapper = mount(<App/>);

wrapper.find('input').simulate('focus');

done();
});

it('should support htmlType=number', (done) => {
let onChange = (value) => {
assert(value === 20);
done();
}, wrapper = mount(<Input defaultValue="abcdef" htmlType="number" onChange={onChange}/>);

wrapper.find('input').simulate('change', {target: {value: '20'}});

done();
});

it('should support htmlType=number value="" ', (done) => {
let onChange = (value) => {
assert(value === '');
done();
}, wrapper = mount(<Input defaultValue="abcdef" htmlType="number" onChange={onChange}/>);

wrapper.find('input').simulate('change', {target: {value: ''}});
});
});
describe('react api', () => {
it('calls componentWillReceiveProps', (done) => {
Expand Down

0 comments on commit 0805a38

Please sign in to comment.