Skip to content

Commit

Permalink
fix(kit): Number has broken zero padding when decimalSeparator eq…
Browse files Browse the repository at this point in the history
…uals to non-default value (#586)
  • Loading branch information
hpieterse authored Oct 12, 2023
1 parent e1e3353 commit 7241761
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand Down
18 changes: 18 additions & 0 deletions projects/kit/src/lib/masks/number/tests/number-mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 7241761

Please sign in to comment.