@canutin/svelte-currency-input 0.6.0 → 0.7.0
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/CurrencyInput.svelte +6 -1
- package/package.json +1 -1
package/CurrencyInput.svelte
CHANGED
|
@@ -32,7 +32,7 @@ const handleKeyDown = (event) => {
|
|
|
32
32
|
};
|
|
33
33
|
let inputTarget;
|
|
34
34
|
const currencyDecimal = new Intl.NumberFormat(locale).format(1.1).charAt(1); // '.' or ','
|
|
35
|
-
const isDecimalComma = currencyDecimal === ',';
|
|
35
|
+
const isDecimalComma = currencyDecimal === ',';
|
|
36
36
|
const currencySymbol = formatCurrency(0, 0)
|
|
37
37
|
.replace('0', '') // e.g. '$0' > '$'
|
|
38
38
|
.replace(/\u00A0/, ''); // e.g '0 €' > '€'
|
|
@@ -41,6 +41,11 @@ const setUnformattedValue = (event) => {
|
|
|
41
41
|
// Don't format if the user is typing a `currencyDecimal` point
|
|
42
42
|
if (event.key === currencyDecimal)
|
|
43
43
|
return;
|
|
44
|
+
// Always convert _the opposite_ decimal key press to the `currencyDecimal` point
|
|
45
|
+
if (isDecimalComma && event.key === '.')
|
|
46
|
+
formattedValue = formattedValue.replace('.', currencyDecimal);
|
|
47
|
+
if (!isDecimalComma && event.key === ',')
|
|
48
|
+
formattedValue = formattedValue.replace(',', currencyDecimal);
|
|
44
49
|
// Don't format if `formattedValue` is ['$', '-$', "-"]
|
|
45
50
|
const ignoreSymbols = [currencySymbol, `-${currencySymbol}`, '-'];
|
|
46
51
|
const strippedUnformattedValue = formattedValue.replace(' ', '');
|