Skip to content

Commit d2703f9

Browse files
author
igor.nepipenko
committed
feat(ref:no-ref): ng21 v6
1 parent 0936d2b commit d2703f9

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 21.0.0(2026-01-28)
2+
3+
### fix
4+
5+
- Fix ([#1590](https://github.com/JsDaddy/ngx-mask/issues/1590))
6+
17
# 20.0.3(2025-08-01)
28

39
### fix

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,12 @@ export class NgxMaskService extends NgxMaskApplierService {
467467
if (!this._renderer || !this._elementRef) {
468468
return;
469469
}
470-
//[TODO]: andriikamaldinov1 find better solution
471-
Promise.resolve().then(() =>
472-
this._renderer?.setProperty(this._elementRef?.nativeElement, name, value)
473-
);
470+
// Use queueMicrotask to defer DOM updates to next microtask.
471+
// This prevents ExpressionChangedAfterItHasBeenCheckedError
472+
// and ensures proper timing with Angular's change detection.
473+
queueMicrotask(() => {
474+
this._renderer?.setProperty(this._elementRef?.nativeElement, name, value);
475+
});
474476
}
475477

476478
public checkDropSpecialCharAmount(mask: string): number {

projects/ngx-mask-lib/src/test/show-mask-typed.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,59 @@ describe('Directive: Mask', () => {
230230
await fixture.whenStable();
231231
expect(inputTarget.value).equal('+38 123/_____');
232232
});
233+
234+
it('should display initial value with showMaskTyped when setValue is used', async () => {
235+
component.mask.set('000-000');
236+
component.showMaskTyped.set(true);
237+
fixture.detectChanges();
238+
239+
// Set initial value via FormControl
240+
component.form.setValue('123456');
241+
fixture.detectChanges();
242+
await fixture.whenStable();
243+
244+
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
245+
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
246+
247+
// The input should show the value with mask, not just the placeholder
248+
expect(inputTarget.value).equal('123-456');
249+
expect(component.form.value).equal('123456');
250+
});
251+
252+
it('should display initial value with showMaskTyped when setValue is used with number', async () => {
253+
component.mask.set('00000');
254+
component.showMaskTyped.set(true);
255+
fixture.detectChanges();
256+
257+
// Set initial value as number (like value = 65432)
258+
component.form.setValue(65432);
259+
fixture.detectChanges();
260+
await fixture.whenStable();
261+
262+
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
263+
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
264+
265+
// The input should show the value, not just the placeholder mask
266+
expect(inputTarget.value).equal('65432');
267+
expect(component.form.value).equal(65432);
268+
});
269+
270+
it('should display initial value with showMaskTyped when config provided at application level', async () => {
271+
// This simulates the user's scenario where showMaskTyped is provided at app level
272+
component.mask.set('(000) 000-0000');
273+
component.showMaskTyped.set(true);
274+
fixture.detectChanges();
275+
276+
// Set initial value
277+
component.form.setValue('1234567890');
278+
fixture.detectChanges();
279+
await fixture.whenStable();
280+
281+
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
282+
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
283+
284+
// Should show formatted value, not just (___) ___-____
285+
expect(inputTarget.value).equal('(123) 456-7890');
286+
expect(component.form.value).equal('1234567890');
287+
});
233288
});

0 commit comments

Comments
 (0)