@@ -121,6 +121,9 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
121121 private _portal : TemplatePortal ;
122122 private _componentDestroyed = false ;
123123
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+
124127 /** Strategy that is used to position the panel. */
125128 private _positionStrategy : ConnectedPositionStrategy ;
126129
@@ -301,25 +304,30 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
301304 }
302305
303306 _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+ }
315314
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 ;
316323 this . _onChange ( value ) ;
317324 this . openPanel ( ) ;
318325 }
319326 }
320327
321328 _handleFocus ( ) : void {
322329 if ( this . _canOpen ( ) ) {
330+ this . _previousValue = this . _element . nativeElement . value ;
323331 this . _attachOverlay ( ) ;
324332 this . _floatLabel ( true ) ;
325333 }
0 commit comments