diff --git a/dist/react-number-format.js b/dist/react-number-format.js index e9518716..dac78489 100644 --- a/dist/react-number-format.js +++ b/dist/react-number-format.js @@ -9,7 +9,7 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) : typeof define === 'function' && define.amd ? define(['react'], factory) : (global = global || self, global.NumberFormat = factory(global.React)); -}(this, function (React) { 'use strict'; +}(this, (React) => { 'use strict'; React = React && React.hasOwnProperty('default') ? React['default'] : React; @@ -20,8 +20,8 @@ } function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; + for (let i = 0; i < props.length; i++) { + const descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; @@ -37,10 +37,10 @@ function _extends() { _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; + for (let i = 1; i < arguments.length; i++) { + const source = arguments[i]; - for (var key in source) { + for (const key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } @@ -111,21 +111,21 @@ * LICENSE file in the root directory of this source tree. */ - var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; + const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; - var ReactPropTypesSecret_1 = ReactPropTypesSecret; + const ReactPropTypesSecret_1 = ReactPropTypesSecret; function emptyFunction() {} function emptyFunctionWithReset() {} emptyFunctionWithReset.resetWarningCache = emptyFunction; - var factoryWithThrowingShims = function() { + const factoryWithThrowingShims = function() { function shim(props, propName, componentName, location, propFullName, secret) { if (secret === ReactPropTypesSecret_1) { // It is still safe when called from React. return; } - var err = new Error( + const err = new Error( 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types' @@ -137,7 +137,7 @@ return shim; } // Important! // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. - var ReactPropTypes = { + const ReactPropTypes = { array: shim, bool: shim, func: shim, @@ -167,7 +167,7 @@ return ReactPropTypes; }; - var propTypes = createCommonjsModule(function (module) { + const propTypes = createCommonjsModule((module) => { /** * Copyright (c) 2013-present, Facebook, Inc. * @@ -207,20 +207,20 @@ } } function applyThousandSeparator(str, thousandSeparator, thousandsGroupStyle) { - var thousandsGroupRegex = getThousandsGroupRegex(thousandsGroupStyle); - var index = str.search(/[1-9]/); + const thousandsGroupRegex = getThousandsGroupRegex(thousandsGroupStyle); + let index = str.search(/[1-9]/); index = index === -1 ? str.length : index; return str.substring(0, index) + str.substring(index, str.length).replace(thousandsGroupRegex, '$1' + thousandSeparator); } //spilt a float number into different parts beforeDecimal, afterDecimal, and negation function splitDecimal(numStr) { - var allowNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - var hasNagation = numStr[0] === '-'; - var addNegation = hasNagation && allowNegative; + const allowNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + const hasNagation = numStr[0] === '-'; + const addNegation = hasNagation && allowNegative; numStr = numStr.replace('-', ''); - var parts = numStr.split('.'); - var beforeDecimal = parts[0]; - var afterDecimal = parts[1] || ''; + const parts = numStr.split('.'); + const beforeDecimal = parts[0]; + const afterDecimal = parts[1] || ''; return { beforeDecimal: beforeDecimal, afterDecimal: afterDecimal, @@ -230,11 +230,11 @@ } function fixLeadingZero(numStr) { if (!numStr) return numStr; - var isNegative = numStr[0] === '-'; + const isNegative = numStr[0] === '-'; if (isNegative) numStr = numStr.substring(1, numStr.length); - var parts = numStr.split('.'); - var beforeDecimal = parts[0].replace(/^0+/, '') || '0'; - var afterDecimal = parts[1] || ''; + const parts = numStr.split('.'); + const beforeDecimal = parts[0].replace(/^0+/, '') || '0'; + const afterDecimal = parts[1] || ''; return "".concat(isNegative ? '-' : '').concat(beforeDecimal).concat(afterDecimal ? ".".concat(afterDecimal) : ''); } /** @@ -243,10 +243,10 @@ */ function limitToScale(numStr, scale, fixedDecimalScale) { - var str = ''; - var filler = fixedDecimalScale ? '0' : ''; + let str = ''; + const filler = fixedDecimalScale ? '0' : ''; - for (var i = 0; i <= scale - 1; i++) { + for (let i = 0; i <= scale - 1; i++) { str += numStr[i] || filler; } @@ -260,29 +260,29 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) { //if number is empty don't do anything return empty string if (['', '-'].indexOf(numStr) !== -1) return numStr; - var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale; + const shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale; - var _splitDecimal = splitDecimal(numStr), + const _splitDecimal = splitDecimal(numStr), beforeDecimal = _splitDecimal.beforeDecimal, afterDecimal = _splitDecimal.afterDecimal, hasNagation = _splitDecimal.hasNagation; - var roundedDecimalParts = parseFloat("0.".concat(afterDecimal || '0')).toFixed(scale).split('.'); - var intPart = beforeDecimal.split('').reverse().reduce(function (roundedStr, current, idx) { + const roundedDecimalParts = parseFloat("0.".concat(afterDecimal || '0')).toFixed(scale).split('.'); + const intPart = beforeDecimal.split('').reverse().reduce((roundedStr, current, idx) => { if (roundedStr.length > idx) { return (Number(roundedStr[0]) + Number(current)).toString() + roundedStr.substring(1, roundedStr.length); } return current + roundedStr; }, roundedDecimalParts[0]); - var decimalPart = limitToScale(roundedDecimalParts[1] || '', Math.min(scale, afterDecimal.length), fixedDecimalScale); - var negation = hasNagation ? '-' : ''; - var decimalSeparator = shoudHaveDecimalSeparator ? '.' : ''; + const decimalPart = limitToScale(roundedDecimalParts[1] || '', Math.min(scale, afterDecimal.length), fixedDecimalScale); + const negation = hasNagation ? '-' : ''; + const decimalSeparator = shoudHaveDecimalSeparator ? '.' : ''; return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart); } function omit(obj, keyMaps) { - var filteredObj = {}; - Object.keys(obj).forEach(function (key) { + const filteredObj = {}; + Object.keys(obj).forEach((key) => { if (!keyMaps[key]) filteredObj[key] = obj[key]; }); return filteredObj; @@ -296,7 +296,7 @@ if (el !== null) { if (el.createTextRange) { - var range = el.createTextRange(); + const range = el.createTextRange(); range.move('character', caretPos); range.select(); return true; @@ -322,10 +322,10 @@ */ function findChangedIndex(prevValue, newValue) { - var i = 0, + let i = 0, j = 0; - var prevLength = prevValue.length; - var newLength = newValue.length; + const prevLength = prevValue.length; + const newLength = newValue.length; while (prevValue[i] === newValue[i] && i < prevLength) { i++; @@ -353,7 +353,7 @@ return Math.max(el.selectionStart, el.selectionEnd); } - var propTypes$1 = { + const propTypes$1 = { thousandSeparator: propTypes.oneOfType([propTypes.string, propTypes.oneOf([true])]), decimalSeparator: propTypes.string, allowedDecimalSeparators: propTypes.arrayOf(propTypes.string), @@ -384,7 +384,7 @@ renderText: propTypes.func, getInputRef: propTypes.func }; - var defaultProps = { + const defaultProps = { displayType: 'input', decimalSeparator: '.', thousandsGroupStyle: 'thousand', @@ -405,22 +405,22 @@ isAllowed: returnTrue }; - var NumberFormat = + const NumberFormat = /*#__PURE__*/ function (_React$Component) { _inherits(NumberFormat, _React$Component); function NumberFormat(props) { - var _this; + let _this; _classCallCheck(this, NumberFormat); _this = _possibleConstructorReturn(this, _getPrototypeOf(NumberFormat).call(this, props)); - var defaultValue = props.defaultValue; //validate props + const defaultValue = props.defaultValue; //validate props _this.validateProps(); - var formattedValue = _this.formatValueProp(defaultValue); + const formattedValue = _this.formatValueProp(defaultValue); _this.state = { value: formattedValue, @@ -446,21 +446,21 @@ }, { key: "updateValueIfRequired", value: function updateValueIfRequired(prevProps) { - var props = this.props, + const props = this.props, state = this.state, focusedElm = this.focusedElm; - var stateValue = state.value, + const stateValue = state.value, _state$numAsString = state.numAsString, lastNumStr = _state$numAsString === void 0 ? '' : _state$numAsString; if (prevProps !== props) { //validate props this.validateProps(); - var lastValueWithNewFormat = this.formatNumString(lastNumStr); - var formattedValue = props.value === undefined ? lastValueWithNewFormat : this.formatValueProp(); - var numAsString = this.removeFormatting(formattedValue); - var floatValue = parseFloat(numAsString); - var lastFloatValue = parseFloat(lastNumStr); + const lastValueWithNewFormat = this.formatNumString(lastNumStr); + const formattedValue = props.value === undefined ? lastValueWithNewFormat : this.formatValueProp(); + const numAsString = this.removeFormatting(formattedValue); + const floatValue = parseFloat(numAsString); + const lastFloatValue = parseFloat(lastNumStr); if ( //while typing set state only when float value changes (!isNaN(floatValue) || !isNaN(lastFloatValue)) && floatValue !== lastFloatValue || //can also set state when float value is same and the format props changes @@ -479,15 +479,15 @@ }, { key: "getFloatString", value: function getFloatString() { - var num = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var decimalScale = this.props.decimalScale; + let num = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + const decimalScale = this.props.decimalScale; - var _this$getSeparators = this.getSeparators(), + const _this$getSeparators = this.getSeparators(), decimalSeparator = _this$getSeparators.decimalSeparator; - var numRegex = this.getNumberRegex(true); //remove negation for regex check + const numRegex = this.getNumberRegex(true); //remove negation for regex check - var hasNegation = num[0] === '-'; + const hasNegation = num[0] === '-'; if (hasNegation) num = num.replace('-', ''); //if decimal scale is zero remove decimal and number after decimalSeparator if (decimalSeparator && decimalScale === 0) { @@ -496,7 +496,7 @@ num = (num.match(numRegex) || []).join('').replace(decimalSeparator, '.'); //remove extra decimals - var firstDecimalIndex = num.indexOf('.'); + const firstDecimalIndex = num.indexOf('.'); if (firstDecimalIndex !== -1) { num = "".concat(num.substring(0, firstDecimalIndex), ".").concat(num.substring(firstDecimalIndex + 1, num.length).replace(new RegExp(escapeRegExp(decimalSeparator), 'g'), '')); @@ -510,11 +510,11 @@ }, { key: "getNumberRegex", value: function getNumberRegex(g, ignoreDecimalSeparator) { - var _this$props = this.props, + const _this$props = this.props, format = _this$props.format, decimalScale = _this$props.decimalScale; - var _this$getSeparators2 = this.getSeparators(), + const _this$getSeparators2 = this.getSeparators(), decimalSeparator = _this$getSeparators2.decimalSeparator; return new RegExp('\\d' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && !format ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined); @@ -522,8 +522,8 @@ }, { key: "getSeparators", value: function getSeparators() { - var decimalSeparator = this.props.decimalSeparator; - var _this$props2 = this.props, + const decimalSeparator = this.props.decimalSeparator; + let _this$props2 = this.props, thousandSeparator = _this$props2.thousandSeparator, allowedDecimalSeparators = _this$props2.allowedDecimalSeparators; @@ -544,7 +544,7 @@ }, { key: "getMaskAtIndex", value: function getMaskAtIndex(index) { - var _this$props$mask = this.props.mask, + const _this$props$mask = this.props.mask, mask = _this$props$mask === void 0 ? ' ' : _this$props$mask; if (typeof mask === 'string') { @@ -556,7 +556,7 @@ }, { key: "getValueObject", value: function getValueObject(formattedValue, numAsString) { - var floatValue = parseFloat(numAsString); + const floatValue = parseFloat(numAsString); return { formattedValue: formattedValue, value: numAsString, @@ -566,9 +566,9 @@ }, { key: "validateProps", value: function validateProps() { - var mask = this.props.mask; //validate decimalSeparator and thousandSeparator + const mask = this.props.mask; //validate decimalSeparator and thousandSeparator - var _this$getSeparators3 = this.getSeparators(), + const _this$getSeparators3 = this.getSeparators(), decimalSeparator = _this$getSeparators3.decimalSeparator, thousandSeparator = _this$getSeparators3.thousandSeparator; @@ -578,7 +578,7 @@ if (mask) { - var maskAsStr = mask === 'string' ? mask : mask.toString(); + const maskAsStr = mask === 'string' ? mask : mask.toString(); if (maskAsStr.match(/\d/g)) { throw new Error("\n Mask ".concat(mask, " should not contain numeric character;\n ")); @@ -596,7 +596,7 @@ otherwise browser resets the caret position after we set it We are also setting it without timeout so that in normal browser we don't see the flickering */ setCaretPosition(el, caretPos); - setTimeout(function () { + setTimeout(() => { if (el.value === currentValue) setCaretPosition(el, caretPos); }, 0); } @@ -605,7 +605,7 @@ }, { key: "correctCaretPosition", value: function correctCaretPosition(value, caretPos, direction) { - var _this$props3 = this.props, + const _this$props3 = this.props, prefix = _this$props3.prefix, suffix = _this$props3.suffix, format = _this$props3.format; //if value is empty return 0 @@ -615,7 +615,7 @@ caretPos = clamp(caretPos, 0, value.length); //in case of format as number limit between prefix and suffix if (!format) { - var hasNegation = value[0] === '-'; + const hasNegation = value[0] === '-'; return clamp(caretPos, prefix.length + (hasNegation ? 1 : 0), value.length - suffix.length); } //in case if custom format method don't do anything @@ -628,19 +628,19 @@ if (format[caretPos - 1] === '#' && charIsNumber(value[caretPos - 1])) return caretPos; //find the nearest caret position - var firstHashPosition = format.indexOf('#'); - var lastHashPosition = format.lastIndexOf('#'); //limit the cursor between the first # position and the last # position + const firstHashPosition = format.indexOf('#'); + const lastHashPosition = format.lastIndexOf('#'); //limit the cursor between the first # position and the last # position caretPos = clamp(caretPos, firstHashPosition, lastHashPosition + 1); - var nextPos = format.substring(caretPos, format.length).indexOf('#'); - var caretLeftBound = caretPos; - var caretRightBound = caretPos + (nextPos === -1 ? 0 : nextPos); //get the position where the last number is present + const nextPos = format.substring(caretPos, format.length).indexOf('#'); + let caretLeftBound = caretPos; + const caretRightBound = caretPos + (nextPos === -1 ? 0 : nextPos); //get the position where the last number is present while (caretLeftBound > firstHashPosition && (format[caretLeftBound] !== '#' || !charIsNumber(value[caretLeftBound]))) { caretLeftBound -= 1; } - var goToLeft = !charIsNumber(value[caretRightBound]) || direction === 'left' && caretPos !== firstHashPosition || caretPos - caretLeftBound < caretRightBound - caretPos; + const goToLeft = !charIsNumber(value[caretRightBound]) || direction === 'left' && caretPos !== firstHashPosition || caretPos - caretLeftBound < caretRightBound - caretPos; if (goToLeft) { //check if number should be taken after the bound or after it @@ -653,17 +653,17 @@ }, { key: "getCaretPosition", value: function getCaretPosition(inputValue, formattedValue, caretPos) { - var format = this.props.format; - var stateValue = this.state.value; - var numRegex = this.getNumberRegex(true); - var inputNumber = (inputValue.match(numRegex) || []).join(''); - var formattedNumber = (formattedValue.match(numRegex) || []).join(''); - var j, i; + const format = this.props.format; + const stateValue = this.state.value; + const numRegex = this.getNumberRegex(true); + const inputNumber = (inputValue.match(numRegex) || []).join(''); + const formattedNumber = (formattedValue.match(numRegex) || []).join(''); + let j, i; j = 0; for (i = 0; i < caretPos; i++) { - var currentInputChar = inputValue[i] || ''; - var currentFormatChar = formattedValue[j] || ''; //no need to increase new cursor position if formatted value does not have those characters + const currentInputChar = inputValue[i] || ''; + const currentFormatChar = formattedValue[j] || ''; //no need to increase new cursor position if formatted value does not have those characters //case inputValue = 1a23 and formattedValue = 123 if (!currentInputChar.match(numRegex) && currentInputChar !== currentFormatChar) continue; //When we are striping out leading zeros maintain the new cursor position @@ -694,19 +694,19 @@ }, { key: "removePrefixAndSuffix", value: function removePrefixAndSuffix(val) { - var _this$props4 = this.props, + const _this$props4 = this.props, format = _this$props4.format, prefix = _this$props4.prefix, suffix = _this$props4.suffix; //remove prefix and suffix if (!format && val) { - var isNegative = val[0] === '-'; //remove negation sign + const isNegative = val[0] === '-'; //remove negation sign if (isNegative) val = val.substring(1, val.length); //remove prefix val = prefix && val.indexOf(prefix) === 0 ? val.substring(prefix.length, val.length) : val; //remove suffix - var suffixLastIndex = val.lastIndexOf(suffix); + const suffixLastIndex = val.lastIndexOf(suffix); val = suffix && suffixLastIndex !== -1 && suffixLastIndex === val.length - suffix.length ? val.substring(0, suffixLastIndex) : val; //add negation sign back if (isNegative) val = '-' + val; @@ -717,18 +717,18 @@ }, { key: "removePatternFormatting", value: function removePatternFormatting(val) { - var format = this.props.format; - var formatArray = format.split('#').filter(function (str) { + const format = this.props.format; + const formatArray = format.split('#').filter((str) => { return str !== ''; }); - var start = 0; - var numStr = ''; + let start = 0; + let numStr = ''; - for (var i = 0, ln = formatArray.length; i <= ln; i++) { - var part = formatArray[i] || ''; //if i is the last fragment take the index of end of the value + for (let i = 0, ln = formatArray.length; i <= ln; i++) { + const part = formatArray[i] || ''; //if i is the last fragment take the index of end of the value //For case like +1 (911) 911 91 91 having pattern +1 (###) ### ## ## - var index = i === ln ? val.length : val.indexOf(part, start); + const index = i === ln ? val.length : val.indexOf(part, start); /* in any case if we don't find the pattern part in the value assume the val as numeric string This will be also in case if user has started typing, in any other case it will not be -1 unless wrong prop value is provided */ @@ -747,7 +747,7 @@ }, { key: "removeFormatting", value: function removeFormatting(val) { - var _this$props5 = this.props, + const _this$props5 = this.props, format = _this$props5.format, removeFormatting = _this$props5.removeFormatting; if (!val) return val; @@ -779,11 +779,11 @@ }, { key: "formatWithPattern", value: function formatWithPattern(numStr) { - var format = this.props.format; - var hashCount = 0; - var formattedNumberAry = format.split(''); + const format = this.props.format; + let hashCount = 0; + const formattedNumberAry = format.split(''); - for (var i = 0, ln = format.length; i < ln; i++) { + for (let i = 0, ln = format.length; i < ln; i++) { if (format[i] === '#') { formattedNumberAry[i] = numStr[hashCount] || this.getMaskAtIndex(hashCount); hashCount += 1; @@ -800,7 +800,7 @@ }, { key: "formatAsNumber", value: function formatAsNumber(numStr) { - var _this$props6 = this.props, + const _this$props6 = this.props, decimalScale = _this$props6.decimalScale, fixedDecimalScale = _this$props6.fixedDecimalScale, prefix = _this$props6.prefix, @@ -808,13 +808,13 @@ allowNegative = _this$props6.allowNegative, thousandsGroupStyle = _this$props6.thousandsGroupStyle; - var _this$getSeparators4 = this.getSeparators(), + const _this$getSeparators4 = this.getSeparators(), thousandSeparator = _this$getSeparators4.thousandSeparator, decimalSeparator = _this$getSeparators4.decimalSeparator; - var hasDecimalSeparator = numStr.indexOf('.') !== -1 || decimalScale && fixedDecimalScale; + const hasDecimalSeparator = numStr.indexOf('.') !== -1 || decimalScale && fixedDecimalScale; - var _splitDecimal = splitDecimal(numStr, allowNegative), + let _splitDecimal = splitDecimal(numStr, allowNegative), beforeDecimal = _splitDecimal.beforeDecimal, afterDecimal = _splitDecimal.afterDecimal, addNegation = _splitDecimal.addNegation; // eslint-disable-line prefer-const @@ -838,11 +838,11 @@ }, { key: "formatNumString", value: function formatNumString() { - var numStr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var _this$props7 = this.props, + const numStr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + const _this$props7 = this.props, format = _this$props7.format, allowEmptyFormatting = _this$props7.allowEmptyFormatting; - var formattedValue = numStr; + let formattedValue = numStr; if (numStr === '' && !allowEmptyFormatting) { formattedValue = ''; @@ -861,16 +861,16 @@ }, { key: "formatValueProp", value: function formatValueProp(defaultValue) { - var _this$props8 = this.props, + const _this$props8 = this.props, format = _this$props8.format, decimalScale = _this$props8.decimalScale, fixedDecimalScale = _this$props8.fixedDecimalScale, allowEmptyFormatting = _this$props8.allowEmptyFormatting; - var _this$props9 = this.props, + let _this$props9 = this.props, _this$props9$value = _this$props9.value, value = _this$props9$value === void 0 ? defaultValue : _this$props9$value, isNumericString = _this$props9.isNumericString; - var isNonNumericFalsy = !value && value !== 0; + const isNonNumericFalsy = !value && value !== 0; if (isNonNumericFalsy && allowEmptyFormatting) { value = ''; @@ -895,20 +895,20 @@ value = roundToPrecision(value, decimalScale, fixedDecimalScale); } - var formattedValue = isNumericString ? this.formatNumString(value) : this.formatInput(value); + const formattedValue = isNumericString ? this.formatNumString(value) : this.formatInput(value); return formattedValue; } }, { key: "formatNegation", value: function formatNegation() { - var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var allowNegative = this.props.allowNegative; - var negationRegex = new RegExp('(-)'); - var doubleNegationRegex = new RegExp('(-)(.)*(-)'); // Check number has '-' value + let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + const allowNegative = this.props.allowNegative; + const negationRegex = new RegExp('(-)'); + const doubleNegationRegex = new RegExp('(-)(.)*(-)'); // Check number has '-' value - var hasNegation = negationRegex.test(value); // Check number has 2 or more '-' values + const hasNegation = negationRegex.test(value); // Check number has 2 or more '-' values - var removeNegation = doubleNegationRegex.test(value); //remove negation + const removeNegation = doubleNegationRegex.test(value); //remove negation value = value.replace(/-/g, ''); @@ -921,8 +921,8 @@ }, { key: "formatInput", value: function formatInput() { - var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var format = this.props.format; //format negation only if we are formatting as number + let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; + const format = this.props.format; //format negation only if we are formatting as number if (!format) { value = this.removePrefixAndSuffix(value); @@ -938,14 +938,14 @@ }, { key: "isCharacterAFormat", value: function isCharacterAFormat(caretPos, value) { - var _this$props10 = this.props, + const _this$props10 = this.props, format = _this$props10.format, prefix = _this$props10.prefix, suffix = _this$props10.suffix, decimalScale = _this$props10.decimalScale, fixedDecimalScale = _this$props10.fixedDecimalScale; - var _this$getSeparators5 = this.getSeparators(), + const _this$getSeparators5 = this.getSeparators(), decimalSeparator = _this$getSeparators5.decimalSeparator; //check within format pattern @@ -960,7 +960,7 @@ }, { key: "checkIfFormatGotDeleted", value: function checkIfFormatGotDeleted(start, end, value) { - for (var i = start; i < end; i++) { + for (let i = start; i < end; i++) { if (this.isCharacterAFormat(i, value)) return true; } @@ -974,22 +974,22 @@ }, { key: "correctInputValue", value: function correctInputValue(caretPos, lastValue, value) { - var _this$props11 = this.props, + const _this$props11 = this.props, format = _this$props11.format, allowNegative = _this$props11.allowNegative, prefix = _this$props11.prefix, suffix = _this$props11.suffix; - var _this$getSeparators6 = this.getSeparators(), + const _this$getSeparators6 = this.getSeparators(), allowedDecimalSeparators = _this$getSeparators6.allowedDecimalSeparators, decimalSeparator = _this$getSeparators6.decimalSeparator; - var lastNumStr = this.state.numAsString || ''; - var _this$selectionBefore = this.selectionBeforeInput, + const lastNumStr = this.state.numAsString || ''; + const _this$selectionBefore = this.selectionBeforeInput, selectionStart = _this$selectionBefore.selectionStart, selectionEnd = _this$selectionBefore.selectionEnd; - var _findChangedIndex = findChangedIndex(lastValue, value), + const _findChangedIndex = findChangedIndex(lastValue, value), start = _findChangedIndex.start, end = _findChangedIndex.end; /** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */ @@ -1004,8 +1004,8 @@ */ - var leftBound = !!format ? 0 : prefix.length; - var rightBound = lastValue.length - (!!format ? 0 : suffix.length); + const leftBound = !!format ? 0 : prefix.length; + const rightBound = lastValue.length - (!!format ? 0 : suffix.length); if (value.length > lastValue.length || !value.length || start === end || selectionStart === 0 && selectionEnd === lastValue.length || selectionStart === leftBound && selectionEnd === rightBound) { return value; @@ -1019,16 +1019,16 @@ if (!format) { - var numericString = this.removeFormatting(value); + const numericString = this.removeFormatting(value); - var _splitDecimal2 = splitDecimal(numericString, allowNegative), + let _splitDecimal2 = splitDecimal(numericString, allowNegative), beforeDecimal = _splitDecimal2.beforeDecimal, afterDecimal = _splitDecimal2.afterDecimal, addNegation = _splitDecimal2.addNegation; // eslint-disable-line prefer-const //clear only if something got deleted - var isBeforeDecimalPoint = caretPos < value.indexOf(decimalSeparator) + 1; + const isBeforeDecimalPoint = caretPos < value.indexOf(decimalSeparator) + 1; if (numericString.length < lastNumStr.length && isBeforeDecimalPoint && beforeDecimal === '' && !parseFloat(afterDecimal)) { return addNegation ? '-' : ''; @@ -1042,21 +1042,21 @@ }, { key: "updateValue", value: function updateValue(params) { - var _this2 = this; + const _this2 = this; - var onUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; - var formattedValue = params.formattedValue, + const onUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; + const formattedValue = params.formattedValue, input = params.input; - var numAsString = params.numAsString, + let numAsString = params.numAsString, caretPos = params.caretPos; - var onValueChange = this.props.onValueChange; - var lastValue = this.state.value; //set caret position, and value imperatively when element is provided + const onValueChange = this.props.onValueChange; + const lastValue = this.state.value; //set caret position, and value imperatively when element is provided if (input) { //calculate caret position if not defined if (!caretPos) { - var inputValue = params.inputValue || input.value; - var currentCaretPosition = getCurrentCaretPosition(input); //get the caret position + const inputValue = params.inputValue || input.value; + const currentCaretPosition = getCurrentCaretPosition(input); //get the caret position caretPos = this.getCaretPosition(inputValue, formattedValue, currentCaretPosition); } //set the value imperatively, this is required for IE fix @@ -1077,7 +1077,7 @@ this.setState({ value: formattedValue, numAsString: numAsString - }, function () { + }, () => { onValueChange(_this2.getValueObject(formattedValue, numAsString)); onUpdate(); }); @@ -1089,17 +1089,17 @@ key: "onChange", value: function onChange(e) { e.persist(); - var el = e.target; - var inputValue = el.value; - var state = this.state, + const el = e.target; + let inputValue = el.value; + const state = this.state, props = this.props; - var isAllowed = props.isAllowed; - var lastValue = state.value || ''; - var currentCaretPosition = getCurrentCaretPosition(el); + const isAllowed = props.isAllowed; + const lastValue = state.value || ''; + const currentCaretPosition = getCurrentCaretPosition(el); inputValue = this.correctInputValue(currentCaretPosition, lastValue, inputValue); - var formattedValue = this.formatInput(inputValue) || ''; - var numAsString = this.removeFormatting(formattedValue); - var valueObj = this.getValueObject(formattedValue, numAsString); + let formattedValue = this.formatInput(inputValue) || ''; + const numAsString = this.removeFormatting(formattedValue); + const valueObj = this.getValueObject(formattedValue, numAsString); if (!isAllowed(valueObj)) { formattedValue = lastValue; @@ -1110,20 +1110,20 @@ numAsString: numAsString, inputValue: inputValue, input: el - }, function () { + }, () => { props.onChange(e); }); } }, { key: "onBlur", value: function onBlur(e) { - var props = this.props, + const props = this.props, state = this.state; - var format = props.format, + const format = props.format, onBlur = props.onBlur, allowLeadingZeros = props.allowLeadingZeros; - var numAsString = state.numAsString; - var lastValue = state.value; + let numAsString = state.numAsString; + const lastValue = state.value; this.focusedElm = null; if (this.focusTimeout) { @@ -1135,7 +1135,7 @@ numAsString = fixLeadingZero(numAsString); } - var formattedValue = this.formatNumString(numAsString); //change the state + const formattedValue = this.formatNumString(numAsString); //change the state if (formattedValue !== lastValue) { // the event needs to be persisted because its properties can be accessed in an asynchronous way @@ -1143,7 +1143,7 @@ this.updateValue({ formattedValue: formattedValue, numAsString: numAsString - }, function () { + }, () => { onBlur(e); }); return; @@ -1155,14 +1155,14 @@ }, { key: "onKeyDown", value: function onKeyDown(e) { - var el = e.target; - var key = e.key; - var selectionStart = el.selectionStart, + const el = e.target; + const key = e.key; + const selectionStart = el.selectionStart, selectionEnd = el.selectionEnd, _el$value = el.value, value = _el$value === void 0 ? '' : _el$value; - var expectedCaretPosition; - var _this$props12 = this.props, + let expectedCaretPosition; + const _this$props12 = this.props, decimalScale = _this$props12.decimalScale, fixedDecimalScale = _this$props12.fixedDecimalScale, prefix = _this$props12.prefix, @@ -1170,10 +1170,10 @@ format = _this$props12.format, onKeyDown = _this$props12.onKeyDown, onValueChange = _this$props12.onValueChange; - var ignoreDecimalSeparator = decimalScale !== undefined && fixedDecimalScale; - var numRegex = this.getNumberRegex(false, ignoreDecimalSeparator); - var negativeRegex = new RegExp('-'); - var isPatternFormat = typeof format === 'string'; + const ignoreDecimalSeparator = decimalScale !== undefined && fixedDecimalScale; + const numRegex = this.getNumberRegex(false, ignoreDecimalSeparator); + const negativeRegex = new RegExp('-'); + const isPatternFormat = typeof format === 'string'; this.selectionBeforeInput = { selectionStart: selectionStart, selectionEnd: selectionEnd //Handle backspace and delete against non numerical/decimal characters or arrow keys @@ -1195,12 +1195,12 @@ return; } - var newCaretPosition = expectedCaretPosition; - var leftBound = isPatternFormat ? format.indexOf('#') : prefix.length; - var rightBound = isPatternFormat ? format.lastIndexOf('#') + 1 : value.length - suffix.length; + let newCaretPosition = expectedCaretPosition; + const leftBound = isPatternFormat ? format.indexOf('#') : prefix.length; + const rightBound = isPatternFormat ? format.lastIndexOf('#') + 1 : value.length - suffix.length; if (key === 'ArrowLeft' || key === 'ArrowRight') { - var direction = key === 'ArrowLeft' ? 'left' : 'right'; + const direction = key === 'ArrowLeft' ? 'left' : 'right'; newCaretPosition = this.correctCaretPosition(value, expectedCaretPosition, direction); } else if (key === 'Delete' && !numRegex.test(value[expectedCaretPosition]) && !negativeRegex.test(value[expectedCaretPosition])) { while (!numRegex.test(value[newCaretPosition]) && newCaretPosition < rightBound) { @@ -1212,7 +1212,7 @@ we will not have any information of keyPress */ if (selectionStart <= leftBound + 1 && value[0] === '-' && typeof format === 'undefined') { - var newValue = value.substring(1); //persist event before performing async task + const newValue = value.substring(1); //persist event before performing async task e.persist(); this.updateValue({ @@ -1248,19 +1248,19 @@ }, { key: "onMouseUp", value: function onMouseUp(e) { - var el = e.target; + const el = e.target; /** * NOTE: we have to give default value for value as in case when custom input is provided * value can come as undefined when nothing is provided on value prop. */ - var selectionStart = el.selectionStart, + const selectionStart = el.selectionStart, selectionEnd = el.selectionEnd, _el$value2 = el.value, value = _el$value2 === void 0 ? '' : _el$value2; if (selectionStart === selectionEnd) { - var caretPosition = this.correctCaretPosition(value, selectionStart); + const caretPosition = this.correctCaretPosition(value, selectionStart); if (caretPosition !== selectionStart) { this.setPatchedCaretPosition(el, caretPosition, value); @@ -1272,20 +1272,20 @@ }, { key: "onFocus", value: function onFocus(e) { - var _this3 = this; + const _this3 = this; // Workaround Chrome and Safari bug https://bugs.chromium.org/p/chromium/issues/detail?id=779328 // (onFocus event target selectionStart is always 0 before setTimeout) e.persist(); this.focusedElm = e.target; - this.focusTimeout = setTimeout(function () { - var el = e.target; - var selectionStart = el.selectionStart, + this.focusTimeout = setTimeout(() => { + const el = e.target; + const selectionStart = el.selectionStart, selectionEnd = el.selectionEnd, _el$value3 = el.value, value = _el$value3 === void 0 ? '' : _el$value3; - var caretPosition = _this3.correctCaretPosition(value, selectionStart); //setPatchedCaretPosition only when everything is not selected on focus (while tabbing into the field) + const caretPosition = _this3.correctCaretPosition(value, selectionStart); //setPatchedCaretPosition only when everything is not selected on focus (while tabbing into the field) if (caretPosition !== selectionStart && !(selectionStart === 0 && selectionEnd === value.length)) { @@ -1298,16 +1298,16 @@ }, { key: "render", value: function render() { - var _this$props13 = this.props, + const _this$props13 = this.props, type = _this$props13.type, displayType = _this$props13.displayType, customInput = _this$props13.customInput, renderText = _this$props13.renderText, getInputRef = _this$props13.getInputRef; - var value = this.state.value; - var otherProps = omit(this.props, propTypes$1); + const value = this.state.value; + const otherProps = omit(this.props, propTypes$1); - var inputProps = _extends({}, otherProps, { + const inputProps = _extends({}, otherProps, { type: type, value: value, onChange: this.onChange, @@ -1322,7 +1322,7 @@ ref: getInputRef }), value); } else if (customInput) { - var CustomInput = customInput; + const CustomInput = customInput; return React.createElement(CustomInput, _extends({}, inputProps, { ref: getInputRef })); diff --git a/lib/number_format.js b/lib/number_format.js index 307732d0..c8a575c2 100644 --- a/lib/number_format.js +++ b/lib/number_format.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +exports["default"] = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); @@ -11,7 +11,7 @@ var _react = _interopRequireDefault(require("react")); var _utils = require("./utils"); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -27,42 +27,42 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - var propTypes = { - thousandSeparator: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.oneOf([true])]), - decimalSeparator: _propTypes.default.string, - allowedDecimalSeparators: _propTypes.default.arrayOf(_propTypes.default.string), - thousandsGroupStyle: _propTypes.default.oneOf(['thousand', 'lakh', 'wan']), - decimalScale: _propTypes.default.number, - fixedDecimalScale: _propTypes.default.bool, - displayType: _propTypes.default.oneOf(['input', 'text']), - prefix: _propTypes.default.string, - suffix: _propTypes.default.string, - format: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]), - removeFormatting: _propTypes.default.func, - mask: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]), - value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), - defaultValue: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), - isNumericString: _propTypes.default.bool, - customInput: _propTypes.default.elementType, - allowNegative: _propTypes.default.bool, - allowEmptyFormatting: _propTypes.default.bool, - allowLeadingZeros: _propTypes.default.bool, - onValueChange: _propTypes.default.func, - onKeyDown: _propTypes.default.func, - onMouseUp: _propTypes.default.func, - onChange: _propTypes.default.func, - onFocus: _propTypes.default.func, - onBlur: _propTypes.default.func, - type: _propTypes.default.oneOf(['text', 'tel', 'password']), - isAllowed: _propTypes.default.func, - renderText: _propTypes.default.func, - getInputRef: _propTypes.default.func + thousandSeparator: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].oneOf([true])]), + decimalSeparator: _propTypes["default"].string, + allowedDecimalSeparators: _propTypes["default"].arrayOf(_propTypes["default"].string), + thousandsGroupStyle: _propTypes["default"].oneOf(['thousand', 'lakh', 'wan']), + decimalScale: _propTypes["default"].number, + fixedDecimalScale: _propTypes["default"].bool, + displayType: _propTypes["default"].oneOf(['input', 'text']), + prefix: _propTypes["default"].string, + suffix: _propTypes["default"].string, + format: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func]), + removeFormatting: _propTypes["default"].func, + mask: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].arrayOf(_propTypes["default"].string)]), + value: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]), + defaultValue: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]), + isNumericString: _propTypes["default"].bool, + customInput: _propTypes["default"].elementType, + allowNegative: _propTypes["default"].bool, + allowEmptyFormatting: _propTypes["default"].bool, + allowLeadingZeros: _propTypes["default"].bool, + onValueChange: _propTypes["default"].func, + onKeyDown: _propTypes["default"].func, + onMouseUp: _propTypes["default"].func, + onChange: _propTypes["default"].func, + onFocus: _propTypes["default"].func, + onBlur: _propTypes["default"].func, + type: _propTypes["default"].oneOf(['text', 'tel', 'password']), + isAllowed: _propTypes["default"].func, + renderText: _propTypes["default"].func, + getInputRef: _propTypes["default"].func }; var defaultProps = { displayType: 'input', @@ -110,11 +110,11 @@ function (_React$Component) { selectionStart: 0, selectionEnd: 0 }; - _this.onChange = _this.onChange.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.onKeyDown = _this.onKeyDown.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.onMouseUp = _this.onMouseUp.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.onFocus = _this.onFocus.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.onBlur = _this.onBlur.bind(_assertThisInitialized(_assertThisInitialized(_this))); + _this.onChange = _this.onChange.bind(_assertThisInitialized(_this)); + _this.onKeyDown = _this.onKeyDown.bind(_assertThisInitialized(_this)); + _this.onMouseUp = _this.onMouseUp.bind(_assertThisInitialized(_this)); + _this.onFocus = _this.onFocus.bind(_assertThisInitialized(_this)); + _this.onBlur = _this.onBlur.bind(_assertThisInitialized(_this)); return _this; } @@ -635,15 +635,6 @@ function (_React$Component) { return true; } - return false; - } - }, { - key: "checkIfFormatGotDeleted", - value: function checkIfFormatGotDeleted(start, end, value) { - for (var i = start; i < end; i++) { - if (this.isCharacterAFormat(i, value)) return true; - } - return false; } /** @@ -689,11 +680,6 @@ function (_React$Component) { if (value.length > lastValue.length || !value.length || start === end || selectionStart === 0 && selectionEnd === lastValue.length || selectionStart === leftBound && selectionEnd === rightBound) { return value; - } //if format got deleted reset the value to last value - - - if (this.checkIfFormatGotDeleted(start, end, lastValue)) { - value = lastValue; } //for numbers check if beforeDecimal got deleted and there is nothing after decimal, //clear all numbers in such case while keeping the - sign @@ -722,8 +708,6 @@ function (_React$Component) { }, { key: "updateValue", value: function updateValue(params) { - var _this2 = this; - var onUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop; var formattedValue = params.formattedValue, input = params.input; @@ -757,10 +741,9 @@ function (_React$Component) { this.setState({ value: formattedValue, numAsString: numAsString - }, function () { - onValueChange(_this2.getValueObject(formattedValue, numAsString)); - onUpdate(); }); + onValueChange(this.getValueObject(formattedValue, numAsString)); + onUpdate(); } else { onUpdate(); } @@ -856,9 +839,8 @@ function (_React$Component) { var isPatternFormat = typeof format === 'string'; this.selectionBeforeInput = { selectionStart: selectionStart, - selectionEnd: selectionEnd //Handle backspace and delete against non numerical/decimal characters or arrow keys - - }; + selectionEnd: selectionEnd + }; //Handle backspace and delete against non numerical/decimal characters or arrow keys if (key === 'ArrowLeft' || key === 'Backspace') { expectedCaretPosition = selectionStart - 1; @@ -952,7 +934,7 @@ function (_React$Component) { }, { key: "onFocus", value: function onFocus(e) { - var _this3 = this; + var _this2 = this; // Workaround Chrome and Safari bug https://bugs.chromium.org/p/chromium/issues/detail?id=779328 // (onFocus event target selectionStart is always 0 before setTimeout) @@ -965,14 +947,14 @@ function (_React$Component) { _el$value3 = el.value, value = _el$value3 === void 0 ? '' : _el$value3; - var caretPosition = _this3.correctCaretPosition(value, selectionStart); //setPatchedCaretPosition only when everything is not selected on focus (while tabbing into the field) + var caretPosition = _this2.correctCaretPosition(value, selectionStart); //setPatchedCaretPosition only when everything is not selected on focus (while tabbing into the field) if (caretPosition !== selectionStart && !(selectionStart === 0 && selectionEnd === value.length)) { - _this3.setPatchedCaretPosition(el, caretPosition, value); + _this2.setPatchedCaretPosition(el, caretPosition, value); } - _this3.props.onFocus(e); + _this2.props.onFocus(e); }, 0); } }, { @@ -998,27 +980,27 @@ function (_React$Component) { }); if (displayType === 'text') { - return renderText ? renderText(value) || null : _react.default.createElement("span", _extends({}, otherProps, { + return renderText ? renderText(value) || null : _react["default"].createElement("span", _extends({}, otherProps, { ref: getInputRef }), value); } else if (customInput) { var CustomInput = customInput; - return _react.default.createElement(CustomInput, _extends({}, inputProps, { + return _react["default"].createElement(CustomInput, _extends({}, inputProps, { ref: getInputRef })); } - return _react.default.createElement("input", _extends({}, inputProps, { + return _react["default"].createElement("input", _extends({}, inputProps, { ref: getInputRef })); } }]); return NumberFormat; -}(_react.default.Component); +}(_react["default"].Component); NumberFormat.propTypes = propTypes; NumberFormat.defaultProps = defaultProps; var _default = NumberFormat; -exports.default = _default; +exports["default"] = _default; module.exports = exports.default; \ No newline at end of file diff --git a/lib/utils.js b/lib/utils.js index 24670152..7f114618 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -26,8 +26,8 @@ function returnTrue() { return true; } -function charIsNumber(char) { - return !!(char || '').match(/\d/); +function charIsNumber(_char) { + return !!(_char || '').match(/\d/); } function escapeRegExp(str) { diff --git a/src/number_format.js b/src/number_format.js index e02ad73d..9cd05ec9 100644 --- a/src/number_format.js +++ b/src/number_format.js @@ -595,12 +595,7 @@ class NumberFormat extends React.Component { return false; } - checkIfFormatGotDeleted(start: number, end: number, value: string) { - for (let i = start; i < end; i++) { - if (this.isCharacterAFormat(i, value)) return true; - } - return false; - } + /** * This will check if any formatting got removed by the delete or backspace and reset the value @@ -634,10 +629,7 @@ class NumberFormat extends React.Component { return value; } - //if format got deleted reset the value to last value - if (this.checkIfFormatGotDeleted(start, end, lastValue)) { - value = lastValue; - } + //for numbers check if beforeDecimal got deleted and there is nothing after decimal, //clear all numbers in such case while keeping the - sign @@ -697,10 +689,9 @@ class NumberFormat extends React.Component { //update state if value is changed if (formattedValue !== lastValue) { - this.setState({value : formattedValue, numAsString}, () => { - onValueChange(this.getValueObject(formattedValue, numAsString)); - onUpdate(); - }); + this.setState({value : formattedValue, numAsString}); + onValueChange(this.getValueObject(formattedValue, numAsString)); + onUpdate(); } else { onUpdate(); } @@ -748,7 +739,7 @@ class NumberFormat extends React.Component { if (!allowLeadingZeros) { numAsString = fixLeadingZero(numAsString); } - + const formattedValue = this.formatNumString(numAsString); //change the state