@syncfusion/ej2-inputs 31.1.22 → 31.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1861,7 +1861,10 @@ let NumericTextBox = class NumericTextBox extends Component {
1861
1861
  modifyText() {
1862
1862
  if (this.value || this.value === 0) {
1863
1863
  const value = this.formatNumber();
1864
- const elementValue = this.isFocused ? value : this.instance.getNumberFormat(this.cultureInfo)(this.value);
1864
+ let elementValue = this.isFocused ? value : this.instance.getNumberFormat(this.cultureInfo)(this.value);
1865
+ if (/[eE]/.test(value)) {
1866
+ elementValue = this.formatScientificNotation(elementValue);
1867
+ }
1865
1868
  this.setElementValue(elementValue);
1866
1869
  attributes(this.element, { 'aria-valuenow': value });
1867
1870
  if (!isNullOrUndefined(this.hiddenInput)) {
@@ -1893,9 +1896,17 @@ let NumericTextBox = class NumericTextBox extends Component {
1893
1896
  const EXPREGEXP = new RegExp('[eE][\-+]?([0-9]+)');
1894
1897
  let valueString = value.toString();
1895
1898
  if (EXPREGEXP.test(valueString)) {
1896
- const result = EXPREGEXP.exec(valueString);
1897
- if (!isNullOrUndefined(result)) {
1898
- valueString = value.toFixed(Math.min(parseInt(result[1], 10), 20));
1899
+ if (/[eE]/.test(valueString)) {
1900
+ valueString = value.toFixed(20).replace(/0+$/, '');
1901
+ if (valueString.charAt(valueString.length - 1) === '.') {
1902
+ valueString = valueString.slice(0, valueString.length - 1);
1903
+ }
1904
+ }
1905
+ else {
1906
+ const result = EXPREGEXP.exec(valueString);
1907
+ if (!isNullOrUndefined(result)) {
1908
+ valueString = value.toFixed(Math.min(parseInt(result[1], 10), 20));
1909
+ }
1899
1910
  }
1900
1911
  }
1901
1912
  const decimalPart = valueString.split('.')[1];
@@ -1907,6 +1918,7 @@ let NumericTextBox = class NumericTextBox extends Component {
1907
1918
  }
1908
1919
  formatNumber() {
1909
1920
  const numberOfDecimals = this.getNumberOfDecimals(this.value);
1921
+ this.storedValueString = this.value.toString();
1910
1922
  return this.instance.getNumberFormat({
1911
1923
  maximumFractionDigits: numberOfDecimals,
1912
1924
  minimumFractionDigits: numberOfDecimals, useGrouping: false
@@ -2018,7 +2030,10 @@ let NumericTextBox = class NumericTextBox extends Component {
2018
2030
  this.isFocused = true;
2019
2031
  this.prevValue = this.value;
2020
2032
  if ((this.value || this.value === 0)) {
2021
- const formatValue = this.formatNumber();
2033
+ let formatValue = this.formatNumber();
2034
+ if (/[eE]/.test(this.value.toString())) {
2035
+ formatValue = this.formatScientificNotation(formatValue);
2036
+ }
2022
2037
  this.setElementValue(formatValue);
2023
2038
  if (!this.isPrevFocused) {
2024
2039
  if (!Browser.isDevice && Browser.info.version === '11.0') {
@@ -2059,7 +2074,10 @@ let NumericTextBox = class NumericTextBox extends Component {
2059
2074
  if (!this.element.value.length) {
2060
2075
  this.setProperties({ value: null }, true);
2061
2076
  }
2062
- const parsedInput = this.instance.getNumberParser({ format: 'n' })(this.element.value);
2077
+ let parsedInput = this.instance.getNumberParser({ format: 'n' })(this.element.value);
2078
+ if (/[eE]/.test(this.element.value)) {
2079
+ parsedInput = parseFloat(this.formatScientificNotation(this.element.value));
2080
+ }
2063
2081
  this.updateValue(parsedInput);
2064
2082
  if (!Browser.isDevice) {
2065
2083
  EventHandler.remove(this.element, 'mousewheel DOMMouseScroll', this.mouseWheel);
@@ -2160,6 +2178,40 @@ let NumericTextBox = class NumericTextBox extends Component {
2160
2178
  EventHandler.remove(this.spinDown, 'mouseleave', this.mouseUpClick);
2161
2179
  }
2162
2180
  }
2181
+ formatScientificNotation(value) {
2182
+ value = this.storedValueString ? this.storedValueString : value;
2183
+ const [base, exponentPart] = value.toLowerCase().split('e');
2184
+ const exponent = parseInt(exponentPart, 10);
2185
+ const match = this.format.match(/n(\d+)/i);
2186
+ const requiredDigits = match ? parseInt(match[1], 10) : 10;
2187
+ const baseDigits = base.replace('.', '');
2188
+ let fullDecimal;
2189
+ if (exponent < 0) {
2190
+ const zerosCount = Math.abs(Number(exponent)) - 1;
2191
+ const limitedZeros = '0'.repeat(Math.min(zerosCount, requiredDigits));
2192
+ fullDecimal = '0.' + limitedZeros + baseDigits;
2193
+ }
2194
+ else {
2195
+ const [intPart, decPart = ''] = base.split('.');
2196
+ const shift = exponent - decPart.length;
2197
+ if (shift >= 0) {
2198
+ fullDecimal = intPart + decPart + '0'.repeat(shift);
2199
+ }
2200
+ else {
2201
+ const newDec = decPart.slice(0, exponent) + '.' + decPart.slice(exponent);
2202
+ fullDecimal = intPart + newDec;
2203
+ }
2204
+ }
2205
+ const [intPart, decPart = ''] = fullDecimal.split('.');
2206
+ if (this.isFocused) {
2207
+ const limitedDecimal = decPart.slice(0, requiredDigits);
2208
+ return `${intPart}.${decPart}`;
2209
+ }
2210
+ else {
2211
+ const formattedDecimal = decPart.padEnd(requiredDigits, '0').slice(0, requiredDigits);
2212
+ return `${intPart}.${formattedDecimal}`;
2213
+ }
2214
+ }
2163
2215
  /**
2164
2216
  * Increments the NumericTextBox value with the specified step value.
2165
2217
  *