Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_processNewValue(value) {
let cursorStart = this.element.selectionStart;
let cursorEnd = this.element.selectionEnd;
let unmaskedValue = this._getUnmaskedValue();
let oldUnmaskedValue = get(this, '_value');
let options = get(this, '_options');
// We only want to make changes if something is different so we don't cause infinite loops or
// double renders.
// We want to make sure that that values we compare are going to come out the same through
// the masking algorithm, to ensure that we only call `update` if the values are actually different
// (e.g. '1234.' will be masked as '1234' and so when `update` is called and passed back
// into the component the decimal will be removed, we don't want this)
if (Inputmask.format(String(oldUnmaskedValue), options) !== Inputmask.format(unmaskedValue, options)) {
this.sendUpdate(unmaskedValue, value);
// When the value is updated, and then sent back down the cursor moves to the end of the field.
// We therefore need to put it back to where the user was typing so they don't get janked around
schedule('afterRender', () => {
this._syncValue();
this.element.setSelectionRange(cursorStart, cursorEnd);
});
}
},