Skip to content

Commit 6ff800f

Browse files
committed
refactor(mask): ignore self drag events
1 parent 1768ad2 commit 6ff800f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

projects/igniteui-angular/src/lib/directives/mask/mask.directive.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA
125125
private _key: number;
126126
private _oldText = '';
127127
private _dataValue = '';
128+
private _focused = false;
128129
private _droppedData: string;
129130
private _hasDropAction: boolean;
130131
private _stopPropagation: boolean;
@@ -222,26 +223,32 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA
222223
/** @hidden */
223224
@HostListener('focus')
224225
public onFocus(): void {
226+
this._focused = true;
225227
this.showMask(this._dataValue);
226228
}
227229

228230
/** @hidden */
229231
@HostListener('blur', ['$event.target.value'])
230232
public onBlur(value: string): void {
233+
this._focused = false;
231234
this.showDisplayValue(value);
232235
this._onTouchedCallback();
233236
}
234237

235238
/** @hidden */
236239
@HostListener('dragenter')
237240
public onDragEnter(): void {
238-
this.showMask(this._dataValue);
241+
if (!this._focused) {
242+
this.showMask(this._dataValue);
243+
}
239244
}
240245

241246
/** @hidden */
242247
@HostListener('dragleave')
243248
public onDragLeave(): void {
244-
this.showDisplayValue(this.inputValue);
249+
if (!this._focused) {
250+
this.showDisplayValue(this.inputValue);
251+
}
245252
}
246253

247254
/** @hidden */
@@ -257,6 +264,7 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA
257264
if (isIE()) {
258265
this._stopPropagation = true;
259266
}
267+
// TODO(D.P.): focusedValuePipe should be deprecated or force-checked to match mask format
260268
this.inputValue = this.focusedValuePipe.transform(value);
261269
} else {
262270
this.inputValue = this.maskParser.applyMask(this.inputValue, this.maskOptions);

src/app/mask/mask.sample.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ <h4>Personal Data</h4>
1212
<label igxLabel for="name">Name</label>
1313
</igx-input-group>
1414
<igx-input-group>
15-
<input igxInput #dateInput name="birthday" type="text" [igxMask]="'00/00/0000'" [(ngModel)]="person.birthday"
15+
<input igxInput #dateInput name="birthday" type="text" [igxMask]="'00/00/0000'" [igxTextSelection]="true" [(ngModel)]="person.birthday"
1616
(blur)="validateDate(dateInput, snackbar)" />
1717
<label igxLabel for="email">Birthday</label>
1818
</igx-input-group>
1919
<igx-input-group>
20-
<input igxInput #ssn name="socialSecurityNumber" type="text" [igxMask]="'###-##-####'"
20+
<input igxInput #ssn name="socialSecurityNumber" type="text" [igxMask]="'###-##-####'" [igxTextSelection]="true"
2121
[(ngModel)]="person.socialSecurityNumber" (blur)="validateSSN(ssn, snackbar)" />
2222
<label igxLabel for="socialSecurityNumber">Social Security Number</label>
2323
</igx-input-group>
2424
<igx-input-group>
25-
<input igxInput #phone name="phone" type="text" [igxMask]="'(####) 00-00-00 Ext. 9999'"
25+
<input igxInput #phone name="phone" type="text" [igxMask]="'(####) 00-00-00 Ext. 9999'" [igxTextSelection]="true"
2626
[(ngModel)]="person.phone" />
2727
<label igxLabel for="phone">Phone</label>
2828
</igx-input-group>

0 commit comments

Comments
 (0)