Skip to content

Commit 5fbab4d

Browse files
fix(ref: no-ref): fix issues
1 parent 19d6c7c commit 5fbab4d

File tree

6 files changed

+69
-8
lines changed

6 files changed

+69
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 20.0.1(2025-07-31)
2+
3+
### fix
4+
5+
- Fix ([#1548](https://github.com/JsDaddy/ngx-mask/issues/1548))
6+
- Fix ([#1551](https://github.com/JsDaddy/ngx-mask/issues/1551))
7+
8+
19
# 20.0.0(2025-07-22)
210

311
### Feature

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mask",
3-
"version": "20.0.0",
3+
"version": "20.0.1",
44
"description": "Awesome ngx mask",
55
"license": "MIT",
66
"engines": {
@@ -127,9 +127,6 @@
127127
"cssnano": "7.1.0",
128128
"postcss-scss": "4.0.9"
129129
},
130-
"overrides": {
131-
"stylus": "0.0.1-security"
132-
},
133130
"typeCoverage": {
134131
"atLeast": 91,
135132
"ignoreObject": true,

projects/ngx-mask-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mask",
3-
"version": "20.0.0",
3+
"version": "20.0.1",
44
"description": "awesome ngx mask",
55
"keywords": [
66
"ng2-mask",

projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ export class NgxMaskApplierService {
100100
let processedValue = inputValue;
101101
let processedPosition = position;
102102

103-
if (processedValue.slice(0, this.prefix.length) === this.prefix) {
104-
processedValue = processedValue.slice(this.prefix.length, processedValue.length);
103+
const startsWithPrefix = processedValue.slice(0, this.prefix.length) === this.prefix;
104+
const pastedFullWithPrefix =
105+
justPasted && processedValue.length === this.prefix.length + maskExpression.length;
106+
const looksLikeFullPrefixPaste =
107+
processedValue === this.prefix + processedValue.slice(this.prefix.length);
108+
109+
if (startsWithPrefix && (pastedFullWithPrefix || looksLikeFullPrefixPaste)) {
110+
processedValue = processedValue.slice(this.prefix.length);
105111
}
106112
if (!!this.suffix && processedValue.length > 0) {
107113
processedValue = this.checkAndRemoveSuffix(processedValue);
@@ -387,7 +393,9 @@ export class NgxMaskApplierService {
387393
result.indexOf(MaskExpression.COMMA) - processedValue.indexOf(MaskExpression.COMMA);
388394
const shiftStep: number = result.length - processedValue.length;
389395
const backspacedDecimalMarkerWithSeparatorLimit =
390-
backspaced && result.length < inputValue.length && this.separatorLimit;
396+
backspaced &&
397+
result.length < inputValue.length - this.suffix.length &&
398+
this.separatorLimit;
391399

392400
if (
393401
(result[processedPosition - 1] === this.thousandSeparator ||

projects/ngx-mask-lib/src/test/add-prefix.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,18 @@ describe('Directive: Mask (Add prefix)', () => {
207207
equal('123', '+38 123', fixture);
208208
equal('1234', '+38 1234', fixture);
209209
});
210+
211+
it('should not remove prefix-like digits from pasted value if it is not a real prefix', () => {
212+
component.mask.set('000/00000');
213+
component.prefix.set('06');
214+
215+
equal('06774/41561', '06774/41561', fixture, false, Paste);
216+
});
217+
218+
it('should remove prefix only if pasted value is real prefix', () => {
219+
component.mask.set('000/00000');
220+
component.prefix.set('06');
221+
222+
equal('06062/41561', '06062/41561', fixture, false, Paste);
223+
});
210224
});

projects/ngx-mask-lib/src/test/delete.cy-spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,38 @@ describe('Directive: Mask (Delete)', () => {
362362
.type('{backspace}'.repeat(5))
363363
.should('have.value', '__:__');
364364
});
365+
366+
it('separator with suffix should replace cursor in right place with thousandSeparator ,', () => {
367+
cy.mount(CypressTestMaskComponent, {
368+
componentProperties: {
369+
mask: signal('separator.2'),
370+
suffix: signal(' EUR'),
371+
thousandSeparator: signal(','),
372+
},
373+
});
374+
375+
cy.get('#masked')
376+
.type('123000')
377+
.should('have.value', '123,000 EUR')
378+
.type('{leftArrow}'.repeat(3))
379+
.type('{backspace}')
380+
.should('have.prop', 'selectionStart', 3);
381+
});
382+
383+
it('separator with suffix should replace cursor in right place with thousandSeparator .', () => {
384+
cy.mount(CypressTestMaskComponent, {
385+
componentProperties: {
386+
mask: signal('separator.2'),
387+
suffix: signal(' EUR'),
388+
thousandSeparator: signal('.'),
389+
},
390+
});
391+
392+
cy.get('#masked')
393+
.type('123000')
394+
.should('have.value', '123.000 EUR')
395+
.type('{leftArrow}'.repeat(3))
396+
.type('{backspace}')
397+
.should('have.prop', 'selectionStart', 3);
398+
});
365399
});

0 commit comments

Comments
 (0)