Skip to content

Commit 02752ec

Browse files
authored
Merge pull request #8410 from IgniteUI/bpenkov/date-picker-focusing-10.1
Prevent IE from focusing DatePicker onload - 10.1.x
2 parents f1e8a80 + 3dfd61f commit 02752ec

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

angular.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
"with": "src/environments/environment.hmr.ts"
7070
}
7171
]
72+
},
73+
"es5": {
74+
"tsConfig": "src/tsconfig-es5.app.json"
7275
}
7376
}
7477
},
@@ -85,6 +88,9 @@
8588
"hmr": true,
8689
"hmrWarning": false,
8790
"browserTarget": "igniteui-dev-demos:build:hmr"
91+
},
92+
"es5": {
93+
"browserTarget": "igniteui-dev-demos:build:es5"
8894
}
8995
}
9096
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve --open --configuration hmr",
7+
"start-es5": "ng serve --configuration es5 -o",
78
"build": "ng build",
89
"test": "ng test",
910
"lint": "ng lint",

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
401401
private _cdr: ChangeDetectorRef,
402402
private _moduleRef: NgModuleRef<any>,
403403
private _injector: Injector,
404-
private _renderer: Renderer2) { }
404+
private _renderer: Renderer2) {
405+
}
406+
405407

406408
/**
407409
* Gets the input group template.
@@ -801,7 +803,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
801803
return this._inputGroup || this._inputGroupUserTemplate || null;
802804
}
803805

804-
/** @hidden @internal */
806+
/** @hidden @internal */
805807
public get inputDirective(): IgxInputDirective {
806808
return this._inputDirective || this._inputDirectiveUserTemplates.first || null;
807809
}
@@ -895,7 +897,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
895897

896898
this._inputDirectiveUserTemplates.changes.subscribe(() => {
897899
this.attachTemplateBlur();
898-
});
900+
});
899901
this.attachTemplateBlur();
900902
}
901903

@@ -911,8 +913,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
911913
this.rawDateString = (res.target as HTMLInputElement).value;
912914
this.onBlur(res, false);
913915
});
914-
// TODO: Refactor custom template handling.
915-
// Revise blur handling when custom template is passed
916+
// TODO: Refactor custom template handling.
917+
// Revise blur handling when custom template is passed
916918
}
917919
}
918920

@@ -1151,6 +1153,12 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
11511153

11521154
/** @hidden @internal */
11531155
public onInput(event) {
1156+
/**
1157+
* Fix for #8165 until refactoring (#6483).
1158+
* The IgxDateTimeEditor will be used to handle all inputs, i.e. this handler will be removed.
1159+
* It extends the IgxMaskDirective which contains logic that handles this issue.
1160+
*/
1161+
if (isIE() && !this._isInEditMode && !this.inputGroup.isFocused) { return; }
11541162
const targetValue = event.target.value;
11551163
const cursorPosition = this._getCursorPosition();
11561164
const checkInput = DatePickerUtil.checkForCompleteDateInput(this.dateFormatParts, targetValue);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA
154154
/** @hidden */
155155
public ngOnInit(): void {
156156
if (!this.nativeElement.placeholder) {
157-
this.renderer.setAttribute(this.nativeElement, 'placeholder', this.maskOptions.format);
157+
this.renderer.setAttribute(this.nativeElement, 'placeholder', this.maskOptions.format);
158158
}
159159
}
160160

@@ -188,7 +188,15 @@ export class IgxMaskDirective implements OnInit, AfterViewChecked, ControlValueA
188188
/** @hidden */
189189
@HostListener('input')
190190
public onInputChanged(): void {
191-
if (isIE() && this._stopPropagation) {
191+
/**
192+
* '!this._focused' is a fix for #8165
193+
* On page load IE triggers input events before focus events and
194+
* it does so for every single input on the page.
195+
* The mask needs to be prevented from doing anything while this is happening because
196+
* the end user will be unable to blur the input.
197+
* https://stackoverflow.com/questions/21406138/input-event-triggered-on-internet-explorer-when-placeholder-changed
198+
*/
199+
if (isIE() && (this._stopPropagation || !this._focused)) {
192200
this._stopPropagation = false;
193201
return;
194202
}

src/tsconfig-es5.app.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.app.json",
3+
"compilerOptions": {
4+
"target": "es5"
5+
}
6+
}

0 commit comments

Comments
 (0)