@bpmn-io/form-js-viewer 0.10.0-alpha.2 → 0.10.0-alpha.3
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.
package/dist/index.es.js
CHANGED
|
@@ -572,16 +572,16 @@ function countDecimals(number) {
|
|
|
572
572
|
function isValidNumber(value) {
|
|
573
573
|
return (typeof value === 'number' || typeof value === 'string') && value !== '' && !isNaN(Number(value));
|
|
574
574
|
}
|
|
575
|
-
function willKeyProduceValidNumber(key, previousValue,
|
|
575
|
+
function willKeyProduceValidNumber(key, previousValue, caretIndex, selectionWidth, decimalDigits) {
|
|
576
576
|
// Dot and comma are both treated as dot
|
|
577
577
|
previousValue = previousValue.replace(',', '.');
|
|
578
578
|
const isFirstDot = !previousValue.includes('.') && (key === '.' || key === ',');
|
|
579
|
-
const isFirstMinus = !previousValue.includes('-') && key === '-' &&
|
|
579
|
+
const isFirstMinus = !previousValue.includes('-') && key === '-' && caretIndex === 0;
|
|
580
580
|
const keypressIsNumeric = /^[0-9]$/i.test(key);
|
|
581
|
-
const dotIndex = previousValue
|
|
581
|
+
const dotIndex = previousValue === undefined ? -1 : previousValue.indexOf('.');
|
|
582
582
|
|
|
583
|
-
// If the
|
|
584
|
-
const overflowsDecimalSpace = typeof decimalDigits === 'number' && selectionWidth === 0 && dotIndex !== -1 && previousValue.includes('.') && previousValue.split('.')[1].length >= decimalDigits &&
|
|
583
|
+
// If the caret is positioned after a dot, and the current decimal digits count is equal or greater to the maximum, disallow the key press
|
|
584
|
+
const overflowsDecimalSpace = typeof decimalDigits === 'number' && selectionWidth === 0 && dotIndex !== -1 && previousValue.includes('.') && previousValue.split('.')[1].length >= decimalDigits && caretIndex > dotIndex;
|
|
585
585
|
const keypressIsAllowedChar = keypressIsNumeric || decimalDigits !== 0 && isFirstDot || isFirstMinus;
|
|
586
586
|
return keypressIsAllowedChar && !overflowsDecimalSpace;
|
|
587
587
|
}
|
|
@@ -1927,10 +1927,10 @@ function Numberfield(props) {
|
|
|
1927
1927
|
|
|
1928
1928
|
// intercept key presses which would lead to an invalid number
|
|
1929
1929
|
const onKeyPress = e => {
|
|
1930
|
-
const
|
|
1930
|
+
const caretIndex = inputRef.current.selectionStart;
|
|
1931
1931
|
const selectionWidth = inputRef.current.selectionStart - inputRef.current.selectionEnd;
|
|
1932
1932
|
const previousValue = inputRef.current.value;
|
|
1933
|
-
if (!willKeyProduceValidNumber(e.key, previousValue,
|
|
1933
|
+
if (!willKeyProduceValidNumber(e.key, previousValue, caretIndex, selectionWidth, decimalDigits)) {
|
|
1934
1934
|
e.preventDefault();
|
|
1935
1935
|
}
|
|
1936
1936
|
};
|