diff --git a/CHANGELOG.md b/CHANGELOG.md index e7bbd008..ce2bc9d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 17.1.1(2024-07-05) + +### Fix + +- Fix ([#1383](https://github.com/JsDaddy/ngx-mask/issues/1383)) + + # 17.1.0(2024-07-05) ### Fix diff --git a/package.json b/package.json index 49012d0b..5713bfee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.1.0", + "version": "17.1.1", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 4c03ed6b..0b7b1605 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.0", + "version": "17.1.1", "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 10b4b628..c55babf7 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 @@ -504,16 +504,14 @@ export class NgxMaskApplierService { (!maskStartWithMonth && (Number(inputValueSliceCursorPlusTwo) > daysCount || Number(inputValueSliceMinusOnePlusOne) > daysCount || - (this.specialCharacters.includes(inputValueCursorPlusOne) && - !backspaced))) || + this.specialCharacters.includes(inputValueCursorPlusOne))) || (startWithMonthInput ? Number(inputValueSliceMinusOnePlusOne) > daysCount || (!this.specialCharacters.includes(inputValueCursor) && this.specialCharacters.includes(inputValueCursorPlusTwo)) || this.specialCharacters.includes(inputValueCursor) : Number(inputValueSliceCursorPlusTwo) > daysCount || - (this.specialCharacters.includes(inputValueCursorPlusOne) && - !backspaced)) + this.specialCharacters.includes(inputValueCursorPlusOne)) ) { // eslint-disable-next-line no-param-reassign position = !this.leadZeroDateTime ? position + 1 : position; @@ -556,8 +554,7 @@ export class NgxMaskApplierService { ) && this.specialCharacters.includes(inputValueCursorMinusOne) && (Number(inputValueSliceCursorPlusTwo) > monthsCount || - (this.specialCharacters.includes(inputValueCursorPlusOne) && - !backspaced)); + this.specialCharacters.includes(inputValueCursorPlusOne)); // cursor === 5 && without days const day2monthInputDot: boolean = (Number(inputValueSliceCursorPlusTwo) > monthsCount && cursor === 5) || diff --git a/projects/ngx-mask-lib/src/test/delete.spec.ts b/projects/ngx-mask-lib/src/test/delete.spec.ts index f959a385..53dccc64 100644 --- a/projects/ngx-mask-lib/src/test/delete.spec.ts +++ b/projects/ngx-mask-lib/src/test/delete.spec.ts @@ -162,7 +162,7 @@ describe('Directive: Mask (Delete)', () => { key: 'Backspace', keyCode: 8, target: inputTarget, - // eslint-disable-next-line @typescript-eslint/no-empty-function + preventDefault: () => {}, }); debugElement.triggerEventHandler('input', { target: inputTarget }); @@ -185,7 +185,7 @@ describe('Directive: Mask (Delete)', () => { key: 'Backspace', keyCode: 8, target: inputTarget, - // eslint-disable-next-line @typescript-eslint/no-empty-function + preventDefault: () => {}, }); debugElement.triggerEventHandler('input', { target: inputTarget }); @@ -208,7 +208,7 @@ describe('Directive: Mask (Delete)', () => { key: 'Backspace', keyCode: 8, target: inputTarget, - // eslint-disable-next-line @typescript-eslint/no-empty-function + preventDefault: () => {}, }); debugElement.triggerEventHandler('input', { target: inputTarget }); @@ -231,10 +231,79 @@ describe('Directive: Mask (Delete)', () => { key: 'Backspace', keyCode: 8, target: inputTarget, - // eslint-disable-next-line @typescript-eslint/no-empty-function + preventDefault: () => {}, }); debugElement.triggerEventHandler('input', { target: inputTarget }); expect(inputTarget.selectionStart).toEqual(3); }); + + it('date mask should show keep right value d0/M0/0000', () => { + component.mask = 'd0/M0/0000'; + const inputElement = fixture.nativeElement.querySelector('input'); + + inputElement.value = '4/4/4444'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(8, 8); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4/4/444'; + inputElement.setSelectionRange(7, 7); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4/4/44'; + inputElement.setSelectionRange(6, 6); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4/4/4'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('4/4/4'); + }); + + it('date mask should show keep right value d0:M0:0000', () => { + component.mask = 'd0:M0:0000'; + const inputElement = fixture.nativeElement.querySelector('input'); + + inputElement.value = '4:4:4444'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(8, 8); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4:4:444'; + inputElement.setSelectionRange(7, 7); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4:4:44'; + inputElement.setSelectionRange(6, 6); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4:4:4'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('4:4:4'); + }); + + it('date mask should show keep right value d0-M0-0000', () => { + component.mask = 'd0-M0-0000'; + const inputElement = fixture.nativeElement.querySelector('input'); + + inputElement.value = '4-4-4444'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(8, 8); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4-4-444'; + inputElement.setSelectionRange(7, 7); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4-4-44'; + inputElement.setSelectionRange(6, 6); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '4-4-4'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('4-4-4'); + }); });