Skip to content
Merged
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
21 changes: 8 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MaskedInput extends React.Component {
this._onKeyDown = this._onKeyDown.bind(this)
this._onPaste = this._onPaste.bind(this)
this._onKeyPress = this._onKeyPress.bind(this)
this._updateInputSelection = this._updateInputSelection.bind(this)
}

componentWillMount() {
Expand Down Expand Up @@ -132,20 +133,14 @@ class MaskedInput extends React.Component {
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value)

var maskValue = this.mask.getValue()
if (e.target.value !== maskValue) {
// Cut or delete operations will have shortened the value
if (e.target.value.length < maskValue.length) {
var sizeDiff = maskValue.length - e.target.value.length
this._updateMaskSelection()
this.mask.selection.end = this.mask.selection.start + sizeDiff
this.mask.backspace()
}
var value = this._getDisplayValue()
e.target.value = value
if (value) {
this._updateInputSelection()
}
var incomingValue = e.target.value
if (incomingValue !== maskValue) { // only modify mask if form contents actually changed
this._updateMaskSelection()
this.mask.setValue(incomingValue) // write the whole updated value into the mask
e.target.value = this._getDisplayValue() // update the form with pattern applied to the value
this._updateInputSelection()
}

if (this.props.onChange) {
this.props.onChange(e)
}
Expand Down