From d4006f8938c00fdc7755a44d0713b9680e18c365 Mon Sep 17 00:00:00 2001 From: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:16:14 +0300 Subject: [PATCH] fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue --- CHANGELOG.md | 6 +++ package.json | 2 +- projects/ngx-mask-lib/package.json | 2 +- .../src/lib/ngx-mask-applier.service.ts | 4 +- .../ngx-mask-lib/src/test/delete.cy-spec.ts | 51 +++++++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a2a825b..e00c2e53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 17.1.5(2024-07-16) + +### Fix + +- Fix ([#1389](https://github.com/JsDaddy/ngx-mask/issues/1389)) + # 17.1.4(2024-07-16) ### Fix diff --git a/package.json b/package.json index 91c4eb9c..cba20a49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.4", + "version": "17.1.5", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index f0b75121..2d8f30f3 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.4", + "version": "17.1.5", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts index 31feab2b..b3440ef0 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts @@ -275,6 +275,7 @@ export class NgxMaskApplierService { inputValue[position] === decimalMarker; const zeroIndexNumberZero = inputValue[0] === MaskExpression.NUMBER_ZERO; const zeroIndexMinus = inputValue[0] === MaskExpression.MINUS; + const zeroIndexThousand = inputValue[0] === this.thousandSeparator; const firstIndexDecimalMarker = inputValue[1] === decimalMarker; const firstIndexNumberZero = inputValue[1] === MaskExpression.NUMBER_ZERO; const secondIndexDecimalMarker = inputValue[2] === decimalMarker; @@ -298,9 +299,10 @@ export class NgxMaskApplierService { // eslint-disable-next-line no-param-reassign inputValue = MaskExpression.MINUS + inputValueAfterZero; } + if ( inputValueAfterZero !== MaskExpression.MINUS && - ((position === 0 && !zeroIndexNumberZero) || + ((position === 0 && (zeroIndexNumberZero || zeroIndexThousand)) || (this.allowNegativeNumbers && position === 1 && zeroIndexMinus && diff --git a/projects/ngx-mask-lib/src/test/delete.cy-spec.ts b/projects/ngx-mask-lib/src/test/delete.cy-spec.ts index d05307fe..39d9f168 100644 --- a/projects/ngx-mask-lib/src/test/delete.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/delete.cy-spec.ts @@ -551,4 +551,55 @@ describe('Directive: Mask (Delete)', () => { .type('{backspace}') .should('have.value', '-33'); }); + + it('should correct work after backspace separator.2 when first digit .', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: '.', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('50004') + .should('have.value', '50.004') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '4'); + }); + + it('should correct work after backspace separator.2 when first digit ,', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: ',', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('50004') + .should('have.value', '50,004') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '4'); + }); + + it('should correct work after backspace separator.2 when first digit whitespace', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: ' ', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('50004') + .should('have.value', '50 004') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '4'); + }); });