From 72417614dd4974c22854dfacc2ee35044c080074 Mon Sep 17 00:00:00 2001 From: Hein <22915998+hpieterse@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:41:05 +0200 Subject: [PATCH] fix(kit): `Number` has broken zero padding when `decimalSeparator` equals to non-default value (#586) --- .../decimal-zero-padding-postprocessor.ts | 2 +- .../lib/masks/number/tests/number-mask.spec.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts b/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts index 3e57df80a..9b5c21260 100644 --- a/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts +++ b/projects/kit/src/lib/masks/number/processors/decimal-zero-padding-postprocessor.ts @@ -26,7 +26,7 @@ export function createDecimalZeroPaddingPostprocessor({ const trailingPostfixRegExp = new RegExp(`${escapeRegExp(postfix)}$`); return ({value, selection}) => { - if (Number.isNaN(maskitoParseNumber(value))) { + if (Number.isNaN(maskitoParseNumber(value, decimalSeparator))) { return {value, selection}; } diff --git a/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts b/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts index a7f61e77f..496ac0b70 100644 --- a/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts +++ b/projects/kit/src/lib/masks/number/tests/number-mask.spec.ts @@ -65,4 +65,22 @@ describe('Number (maskitoTransform)', () => { expect(maskitoTransform('45 001 $', options)).toBe('45 001 $'); // initialization phase expect(maskitoTransform('45 001 $', options)).toBe('45 001 $'); // next user interaction }); + + describe('`thousandSeparator` is equal to the item from `decimalPseudoSeparators` with zero padding', () => { + let options: MaskitoOptions = MASKITO_DEFAULT_OPTIONS; + + beforeEach(() => { + options = maskitoNumberOptionsGenerator({ + decimalSeparator: ',', + thousandSeparator: '.', + decimalPseudoSeparators: ['.', ','], + precision: 2, + decimalZeroPadding: true, + }); + }); + + it('add dots and decimals (21.121.321,00)', () => { + expect(maskitoTransform('21121321', options)).toBe('21.121.321,00'); + }); + }); });