Skip to content

Commit

Permalink
Fix invalid input like '11x'
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Jan 17, 2017
1 parent 7e140ed commit 74ab28e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-input-number",
"version": "3.0.0",
"version": "3.0.1",
"description": "input-number ui component for react(web & react-native)",
"keywords": [
"react",
Expand Down
2 changes: 1 addition & 1 deletion src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {

setValue(v, callback) {
// trigger onChange
const newValue = isNaN(v) || v === '' ? undefined : v;
const newValue = isNaN(parseFloat(v, 10)) ? undefined : parseFloat(v, 10);
const changed = newValue !== this.state.value;
if (!('value' in this.props)) {
this.setState({
Expand Down
10 changes: 10 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ describe('inputNumber', () => {
expect(onChangeFirstArgument).to.be(undefined);
});

it('input invalid string with number', () => {
Simulate.focus(inputElement);
Simulate.change(inputElement, { target: { value: '2x' } });
expect(inputElement.value).to.be('2x');
expect(onChangeFirstArgument).to.be('2x');
Simulate.blur(inputElement);
expect(inputElement.value).to.be('2');
expect(onChangeFirstArgument).to.be(2);
});

it('input negative symbol', () => {
example.setState({ min: -100 });
Simulate.focus(inputElement);
Expand Down

0 comments on commit 74ab28e

Please sign in to comment.