From ce29060424f8418d2d4248723ff84fe4c71f8285 Mon Sep 17 00:00:00 2001 From: Hein Pieterse <22915998+hpieterse@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:32:56 +0200 Subject: [PATCH] fix(kit): use configured decimal seperator in `createDecimalZeroPaddingPostprocessor` --- .../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'); + }); + }); });