Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/bugs #1387

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "17.1.0",
"version": "17.1.1",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "17.1.0",
"version": "17.1.1",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
9 changes: 3 additions & 6 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) ||
Expand Down
77 changes: 73 additions & 4 deletions projects/ngx-mask-lib/src/test/delete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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 });
Expand All @@ -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 });
Expand All @@ -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');
});
});
Loading