Skip to content

Commit fa0b07e

Browse files
Joe Loveiamdustan
authored andcommitted
Can't enter more than one character in Edge browser (insin#79)
* add user agent sniffing for keypress event name (eww) * remove semi-colons to match coding style * fix bug with android chrome, bah * small tweak to (hopefully) fix android chrome) gs * just make it exclude android * rename method
1 parent ad934c3 commit fa0b07e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ var MaskedInput = React.createClass({
235235
return value === this.mask.emptyValue ? '' : value
236236
},
237237

238+
_keyPressPropName() {
239+
return navigator.userAgent.match(/Android/i)
240+
? 'onBeforeInput'
241+
: 'onKeyPress'
242+
},
243+
244+
_getEventHandlers() {
245+
return {
246+
onChange: this._onChange,
247+
onKeyDown: this._onKeyDown,
248+
onPaste: this._onPaste,
249+
[this._keyPressPropName()]: this._onKeyPress
250+
}
251+
},
252+
238253
focus() {
239254
this.input.focus()
240255
},
@@ -244,19 +259,14 @@ var MaskedInput = React.createClass({
244259
},
245260

246261
render() {
247-
var {mask, formatCharacters, size, placeholder, placeholderChar, ...props} = this.props
248-
var patternLength = this.mask.pattern.length
249-
return <input {...props}
250-
ref={r => this.input = r }
251-
maxLength={patternLength}
252-
onChange={this._onChange}
253-
onKeyDown={this._onKeyDown}
254-
onBeforeInput={this._onKeyPress}
255-
onPaste={this._onPaste}
256-
placeholder={placeholder || this.mask.emptyValue}
257-
size={size || patternLength}
258-
value={this._getDisplayValue()}
259-
/>
262+
var ref = r => this.input = r
263+
var maxLength = this.mask.pattern.length
264+
var value = this._getDisplayValue()
265+
var eventHandlers = this._getEventHandlers()
266+
var { size = maxLength, placeholder = this.mask.emptyValue } = this.props
267+
var props = { ...this.props, ...eventHandlers, ref, maxLength, value, size, placeholder }
268+
269+
return <input {...props} />
260270
}
261271
})
262272

0 commit comments

Comments
 (0)