Skip to content

Commit ffae092

Browse files
nathanstittiamdustan
authored andcommitted
Silence React 15.4 invalid property warnings (insin#80)
* Restore console.error after testing it * remove planceHolderChar and formatCharacters props Before passing them to input in order to silence invalid prop warnings introduced in React 15.4
1 parent e31d323 commit ffae092

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ var MaskedInput = React.createClass({
264264
var value = this._getDisplayValue()
265265
var eventHandlers = this._getEventHandlers()
266266
var { size = maxLength, placeholder = this.mask.emptyValue } = this.props
267-
var props = { ...this.props, ...eventHandlers, ref, maxLength, value, size, placeholder }
268267

269-
return <input {...props} />
268+
var {placeholderChar, formatCharacters, ...cleanedProps} = this.props
269+
var inputProps = { ...cleanedProps, ...eventHandlers, ref, maxLength, value, size, placeholder }
270+
return <input {...inputProps} />
270271
}
271272
})
272273

tests/index-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('MaskedInput', () => {
2828
expect(console.error.calls[0].arguments[0]).toMatch(
2929
new RegExp('required', 'i')
3030
)
31+
console.error.restore()
3132
})
3233

3334
it('should handle a masking workflow', () => {
@@ -208,6 +209,27 @@ describe('MaskedInput', () => {
208209
cleanup(el)
209210
})
210211

212+
it('cleans props from input', () => {
213+
const el = setup()
214+
let ref = null
215+
let defaultMask = '1111 1111 1111 1111'
216+
function render(props) {
217+
ReactDOM.render(
218+
<MaskedInput ref={(r) => ref = r} {...props} />,
219+
el
220+
)
221+
}
222+
expect.spyOn(console, 'error')
223+
render({mask: defaultMask, value: '',
224+
placeholderChar: 'X', formatCharacters: {A: null}})
225+
expect(console.error).toNotHaveBeenCalled()
226+
console.error.restore()
227+
let input = ReactDOM.findDOMNode(ref)
228+
expect(input.getAttribute('placeholderChar')).toNotExist()
229+
expect(input.getAttribute('formatCharacters')).toNotExist()
230+
cleanup(el)
231+
})
232+
211233
it('should handle updating multiple values', () => {
212234
const el = setup()
213235
let ref = null

0 commit comments

Comments
 (0)