Skip to content

Commit

Permalink
fix mask value setting on change
Browse files Browse the repository at this point in the history
  • Loading branch information
tx44 committed Sep 2, 2016
1 parent ae57dc2 commit 8ed52a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions tests/index-test.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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(
<MaskedInput
ref={(r) => {
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
Expand Down

0 comments on commit 8ed52a9

Please sign in to comment.