Skip to content

Commit 5fab1d1

Browse files
authored
Merge pull request #8411 from IgniteUI/bpenkov/date-picker-focusing-9.1
Prevent IE from focusing DatePicker onload - 9.1.x
2 parents b5c3821 + 39daf79 commit 5fab1d1

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
@@ -70,6 +70,9 @@
7070
"with": "src/environments/environment.hmr.ts"
7171
}
7272
]
73+
},
74+
"es5": {
75+
"tsConfig": "src/tsconfig-es5.app.json"
7376
}
7477
}
7578
},
@@ -86,6 +89,9 @@
8689
"hmr": true,
8790
"hmrWarning": false,
8891
"browserTarget": "igniteui-dev-demos:build:hmr"
92+
},
93+
"es5": {
94+
"browserTarget": "igniteui-dev-demos:build:es5"
8995
}
9096
}
9197
},

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
@@ -392,7 +392,9 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
392392
private _cdr: ChangeDetectorRef,
393393
private _moduleRef: NgModuleRef<any>,
394394
private _injector: Injector,
395-
private _renderer: Renderer2) { }
395+
private _renderer: Renderer2) {
396+
}
397+
396398

397399
/**
398400
* Gets the input group template.
@@ -792,7 +794,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
792794
return this._inputGroup || this._inputGroupUserTemplate || null;
793795
}
794796

795-
/** @hidden @internal */
797+
/** @hidden @internal */
796798
public get inputDirective(): IgxInputDirective {
797799
return this._inputDirective || this._inputDirectiveUserTemplates.first || null;
798800
}
@@ -885,7 +887,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
885887

886888
this._inputDirectiveUserTemplates.changes.subscribe(() => {
887889
this.attachTemplateBlur();
888-
});
890+
});
889891
this.attachTemplateBlur();
890892
}
891893

@@ -901,8 +903,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
901903
this.rawDateString = (res.target as HTMLInputElement).value;
902904
this.onBlur(res, false);
903905
});
904-
// TODO: Refactor custom template handling.
905-
// Revise blur handling when custom template is passed
906+
// TODO: Refactor custom template handling.
907+
// Revise blur handling when custom template is passed
906908
}
907909
}
908910

@@ -1141,6 +1143,12 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
11411143

11421144
/** @hidden @internal */
11431145
public onInput(event) {
1146+
/**
1147+
* Fix for #8165 until refactoring (#6483).
1148+
* The IgxDateTimeEditor will be used to handle all inputs, i.e. this handler will be removed.
1149+
* It extends the IgxMaskDirective which contains logic that handles this issue.
1150+
*/
1151+
if (isIE() && !this._isInEditMode && !this.inputGroup.isFocused) { return; }
11441152
const targetValue = event.target.value;
11451153
const cursorPosition = this._getCursorPosition();
11461154
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)