diff --git a/CHANGELOG.md b/CHANGELOG.md index 23168c07..b8eceb98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ -# 19.0.5(2024-12-17) +# 19.0.6(2024-12-20) ### Fix - Fix ([#1481](https://github.com/JsDaddy/ngx-mask/issues/1481)) + + +# 19.0.5(2024-12-20) + +### Fix + - Fix ([#1411](https://github.com/JsDaddy/ngx-mask/issues/1411)) # 19.0.4(2024-12-13) diff --git a/package.json b/package.json index 947bed2f..6865e3b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "19.0.5", + "version": "19.0.6", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 7ce1935b..ecc4f2f2 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "19.0.5", + "version": "19.0.6", "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 b5ab3521..d2a8a3f4 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 @@ -200,13 +200,18 @@ export class NgxMaskApplierService { let decimalMarker = this.decimalMarker; if (Array.isArray(this.decimalMarker)) { - const marker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator); - - decimalMarker = marker - ? marker - : this.actualValue.includes(this.decimalMarker[0]) - ? this.decimalMarker[0] - : this.decimalMarker[1]; + if ( + this.actualValue.includes(this.decimalMarker[0]) || + this.actualValue.includes(this.decimalMarker[1]) + ) { + decimalMarker = this.actualValue.includes(this.decimalMarker[0]) + ? this.decimalMarker[0] + : this.decimalMarker[1]; + } else { + decimalMarker = this.decimalMarker.find( + (dm) => dm !== this.thousandSeparator + ) as '.' | ','; + } } if (backspaced) { diff --git a/projects/ngx-mask-lib/src/test/separator.cy-spec.ts b/projects/ngx-mask-lib/src/test/separator.cy-spec.ts index a373041d..9669d26f 100644 --- a/projects/ngx-mask-lib/src/test/separator.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.cy-spec.ts @@ -1,5 +1,6 @@ import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; import { signal } from '@angular/core'; +import type { NgxMaskConfig } from 'ngx-mask'; describe('Test Date Hh:m0', () => { it('Mask separator.2 check cursor with value 100.0', () => { @@ -506,4 +507,82 @@ describe('Test Date Hh:m0', () => { .type('{backspace}') .should('have.value', '0.05'); }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('1000000,35') + .should('have.value', '1 000 000,35') + .type('{leftArrow}'.repeat(11)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('1000000.35') + .should('have.value', '1 000 000.35') + .type('{leftArrow}'.repeat(11)) + .type('{backspace}') + .should('have.value', '0.35'); + }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('60,35') + .should('have.value', '60,35') + .type('{leftArrow}'.repeat(4)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('60.35') + .should('have.value', '60.35') + .type('{leftArrow}'.repeat(4)) + .type('{backspace}') + .should('have.value', '0.35'); + }); + + it('should correct work after backspace separator.2 with default values', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: signal('separator.2'), + decimalMarker: signal(['.', ','] as NgxMaskConfig['decimalMarker']), + thousandSeparator: signal(' '), + }, + }); + + cy.get('#masked') + .type('200,35') + .should('have.value', '200,35') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '0,35'); + + cy.get('#masked').clear(); + + cy.get('#masked') + .type('200.35') + .should('have.value', '200.35') + .type('{leftArrow}'.repeat(5)) + .type('{backspace}') + .should('have.value', '0.35'); + }); });