Skip to content

Commit

Permalink
reinit value and buffer on mask change
Browse files Browse the repository at this point in the history
  • Loading branch information
murzvo committed Feb 13, 2017
1 parent 5c5cd9b commit 5750d9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/MaskedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const MaskedField = React.createClass({
value: propsValue ? this._maskedValue(propsValue) : ''
};
},
componentWillReceiveProps(nextProps) {
if (this.props.mask !== nextProps.mask) {
this.setState({value: ''}, function() { this._buffer = this._initialBuffer(); });
this._cursorPos = this._firstNonMaskIdx;
}
},
componentDidUpdate() {
if (this._cursorPos !== undefined) {
this._setSelection(this._cursorPos);
Expand Down
2 changes: 1 addition & 1 deletion src/SelectionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export function setSelection(node, start, end) {
range.moveStart('character', end);
range.select();
}
}
}

0 comments on commit 5750d9b

Please sign in to comment.