From ae0d5f8ca1db900de9477fd412a98492de252f01 Mon Sep 17 00:00:00 2001 From: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:37:03 +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 +- .../ngx-mask-lib/src/lib/ngx-mask.service.ts | 8 +++++++- .../ngx-mask-lib/src/test/basic-logic.spec.ts | 18 ++++++++++++++++++ .../src/test/utils/test-component.component.ts | 3 +++ 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e00c2e53..ea3b81c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 17.1.6(2024-07-16) + +### Fix + +- Fix ([#1342](https://github.com/JsDaddy/ngx-mask/issues/1342)) + # 17.1.5(2024-07-16) ### Fix diff --git a/package.json b/package.json index cba20a49..eb7c7b5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.5", + "version": "17.1.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 2d8f30f3..760bd584 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.5", + "version": "17.1.6", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts index 7b42ca0b..94ec1d03 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts @@ -155,7 +155,13 @@ export class NgxMaskService extends NgxMaskApplierService { Boolean(newInputValue) && newInputValue.length ? newInputValue : inputValue; } - if (this.showMaskTyped && this.keepCharacterPositions && this.actualValue && !justPasted) { + if ( + this.showMaskTyped && + this.keepCharacterPositions && + this.actualValue && + !justPasted && + !this.writingValue + ) { const value = this.dropSpecialCharacters ? this.removeMask(this.actualValue) : this.actualValue; diff --git a/projects/ngx-mask-lib/src/test/basic-logic.spec.ts b/projects/ngx-mask-lib/src/test/basic-logic.spec.ts index 57997473..01ce9a05 100644 --- a/projects/ngx-mask-lib/src/test/basic-logic.spec.ts +++ b/projects/ngx-mask-lib/src/test/basic-logic.spec.ts @@ -928,4 +928,22 @@ describe('Directive: Mask', () => { equal('123-4-5', '123-4-5', fixture); equal('123-45-6', '123-45-6', fixture); }); + + it('mask 00/00/0000 with keepCharacterPositions should work after setValue', () => { + const debugElement: DebugElement = fixture.debugElement.query(By.css('input')); + const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement; + spyOnProperty(document, 'activeElement').and.returnValue(inputTarget); + fixture.detectChanges(); + + component.mask = '00/00/0000'; + component.showMaskTyped = true; + component.keepCharacterPositions = true; + + equal('11/11/1111', '11/11/1111', fixture); + component.form.setValue('22/22/2222'); + fixture.detectChanges(); + requestAnimationFrame(() => { + expect(inputTarget.value).toBe('22/22/2222'); + }); + }); }); diff --git a/projects/ngx-mask-lib/src/test/utils/test-component.component.ts b/projects/ngx-mask-lib/src/test/utils/test-component.component.ts index 567f7222..9cdcacc8 100644 --- a/projects/ngx-mask-lib/src/test/utils/test-component.component.ts +++ b/projects/ngx-mask-lib/src/test/utils/test-component.component.ts @@ -25,6 +25,7 @@ import { IConfig } from '../../lib/ngx-mask.config'; [allowNegativeNumbers]="allowNegativeNumbers" [leadZeroDateTime]="leadZeroDateTime" [leadZero]="leadZero" + [keepCharacterPositions]="keepCharacterPositions" [apm]="apm" [validation]="validation" [inputTransformFn]="inputTransformFn || null" @@ -53,6 +54,8 @@ export class TestMaskComponent { public specialCharacters: IConfig['specialCharacters'] | undefined; + public keepCharacterPositions: IConfig['keepCharacterPositions'] | undefined; + public showMaskTyped: IConfig['showMaskTyped'] | undefined; public placeHolderCharacter: IConfig['placeHolderCharacter'] | undefined;