diff --git a/projects/igniteui-angular/src/lib/directives/mask/mask.directive.spec.ts b/projects/igniteui-angular/src/lib/directives/mask/mask.directive.spec.ts index 5ea77263222..0cb1e3e9dd5 100644 --- a/projects/igniteui-angular/src/lib/directives/mask/mask.directive.spec.ts +++ b/projects/igniteui-angular/src/lib/directives/mask/mask.directive.spec.ts @@ -7,6 +7,7 @@ import { IgxMaskModule, IgxMaskDirective } from './mask.directive'; import { configureTestSuite } from '../../test-utils/configure-suite'; import { UIInteractions } from '../../test-utils/ui-interactions.spec'; import { Replaced } from './mask-parsing.service'; +import { By } from '@angular/platform-browser'; describe('igxMask', () => { configureTestSuite(); @@ -25,7 +26,8 @@ describe('igxMask', () => { OneWayBindComponent, PipesMaskComponent, PlaceholderMaskComponent, - EmptyMaskTestComponent + EmptyMaskTestComponent, + ReadonlyMaskTestComponent ], imports: [ FormsModule, @@ -369,7 +371,7 @@ describe('igxMask', () => { expect(input.nativeElement.value).toEqual('sss'); })); - it('Apply placehodler when value is not defined.', fakeAsync(() => { + it('Apply placeholder when value is not defined.', fakeAsync(() => { const fixture = TestBed.createComponent(PlaceholderMaskComponent); fixture.detectChanges(); @@ -390,6 +392,23 @@ describe('igxMask', () => { expect(input.nativeElement.value).toEqual(''); expect(input.nativeElement.placeholder).toEqual('hello'); })); + + it('should not enter edit mode if it is marked as readonly', fakeAsync(() => { + const fixture = TestBed.createComponent(ReadonlyMaskTestComponent); + fixture.detectChanges(); + + const maskDirective = fixture.componentInstance.mask; + spyOn(maskDirective, 'onFocus').and.callThrough(); + spyOn(maskDirective, 'showMask').and.callThrough(); + + const input = fixture.debugElement.query(By.css('.igx-input-group__input')); + input.triggerEventHandler('focus', {}); + fixture.detectChanges(); + + expect(maskDirective.onFocus).toHaveBeenCalledTimes(1); + expect((maskDirective as any).showMask).toHaveBeenCalledTimes(0); + expect((maskDirective as any).inputValue).toEqual(''); + })); }); describe('igxMaskDirective ControlValueAccessor Unit', () => { @@ -624,6 +643,16 @@ class EmptyMaskTestComponent { public input: ElementRef; } +@Component({ + template: ` + + ` +}) +class ReadonlyMaskTestComponent { + @ViewChild(IgxMaskDirective) + public mask: IgxMaskDirective; +} + @Pipe({ name: 'inputFormat' }) export class InputFormatPipe implements PipeTransform { transform(value: any): string { diff --git a/projects/igniteui-angular/src/lib/directives/mask/mask.directive.ts b/projects/igniteui-angular/src/lib/directives/mask/mask.directive.ts index a8f3158f6cb..994d03f8190 100644 --- a/projects/igniteui-angular/src/lib/directives/mask/mask.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/mask/mask.directive.ts @@ -234,7 +234,9 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA /** @hidden */ @HostListener('focus') public onFocus(): void { - // TODO: handle readonly + if (this.nativeElement.readOnly) { + return; + } this._focused = true; this.showMask(this._dataValue); }