Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mask value setting on change #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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