@@ -121,6 +121,9 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
121
121
private _portal : TemplatePortal ;
122
122
private _componentDestroyed = false ;
123
123
124
+ /** Old value of the native input. Used to work around issues with the `input` event on IE. */
125
+ private _previousValue : string | number | null ;
126
+
124
127
/** Strategy that is used to position the panel. */
125
128
private _positionStrategy : ConnectedPositionStrategy ;
126
129
@@ -301,25 +304,30 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
301
304
}
302
305
303
306
_handleInput ( event : KeyboardEvent ) : void {
304
- // We need to ensure that the input is focused, because IE will fire the `input`
305
- // event on focus/blur/load if the input has a placeholder. See:
306
- // https://connect.microsoft.com/IE/feedback/details/885747/
307
- if ( this . _canOpen ( ) && document . activeElement === event . target ) {
308
- let target = event . target as HTMLInputElement ;
309
- let value : number | string | null = target . value ;
310
-
311
- // Based on `NumberValueAccessor` from forms.
312
- if ( target . type === 'number' ) {
313
- value = value == '' ? null : parseFloat ( value ) ;
314
- }
307
+ let target = event . target as HTMLInputElement ;
308
+ let value : number | string | null = target . value ;
309
+
310
+ // Based on `NumberValueAccessor` from forms.
311
+ if ( target . type === 'number' ) {
312
+ value = value == '' ? null : parseFloat ( value ) ;
313
+ }
315
314
315
+ // If the input has a placeholder, IE will fire the `input` event on page load,
316
+ // focus and blur, in addition to when the user actually changed the value. To
317
+ // filter out all of the extra events, we save the value on focus and between
318
+ // `input` events, and we check whether it changed.
319
+ // See: https://connect.microsoft.com/IE/feedback/details/885747/
320
+ if ( this . _canOpen ( ) && this . _previousValue !== value &&
321
+ document . activeElement === event . target ) {
322
+ this . _previousValue = value ;
316
323
this . _onChange ( value ) ;
317
324
this . openPanel ( ) ;
318
325
}
319
326
}
320
327
321
328
_handleFocus ( ) : void {
322
329
if ( this . _canOpen ( ) ) {
330
+ this . _previousValue = this . _element . nativeElement . value ;
323
331
this . _attachOverlay ( ) ;
324
332
this . _floatLabel ( true ) ;
325
333
}
0 commit comments