diff --git a/package.json b/package.json index 28182bc..01d3b23 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "eslint-config-jonnybuchanan": "2.0.3", "nwb": "0.9.x", "react": "15.x.x", + "react-addons-test-utils": "15.x.x", "react-dom": "15.x.x" }, "repository": { diff --git a/src/index.js b/src/index.js index 23b2b72..8298e47 100644 --- a/src/index.js +++ b/src/index.js @@ -100,6 +100,9 @@ var MaskedInput = React.createClass({ this.mask.selection.end = this.mask.selection.start + sizeDiff this.mask.backspace() } + else { + this.mask.setValue(e.target.value) + } var value = this._getDisplayValue() e.target.value = value if (value) { diff --git a/tests/index-test.js b/tests/index-test.js index 1179fe6..412921d 100644 --- a/tests/index-test.js +++ b/tests/index-test.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ import React from 'react' import ReactDOM from 'react-dom' +import TestUtils from 'react-addons-test-utils' import expect from 'expect' import MaskedInput from 'src' @@ -205,6 +206,28 @@ describe('MaskedInput', () => { cleanup(el) }) + it('should receive value from event.target in first argument of onChange callback', () => { + const onChange = expect.createSpy() + const el = setup() + let ref = null + ReactDOM.render( + { + if (r) ref = r + }} + mask="11.11.1111" + onChange={ onChange } + />, + el + ) + const input = ReactDOM.findDOMNode(ref) + TestUtils.Simulate.change(input, { target: { value: '99.99.9999' } }) + + expect(onChange.calls[0].arguments[0].target.value).toEqual('99.99.9999') + + cleanup(el) + }) + it('should handle updating multiple values', () => { const el = setup() let ref = null