@@ -21,6 +21,7 @@ import {
21
21
OnInit ,
22
22
Optional ,
23
23
Self ,
24
+ HostListener ,
24
25
} from '@angular/core' ;
25
26
import { FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
26
27
import {
@@ -83,9 +84,6 @@ const _MatInputMixinBase: CanUpdateErrorStateCtor & typeof MatInputBase =
83
84
'[attr.aria-describedby]' : '_ariaDescribedby || null' ,
84
85
'[attr.aria-invalid]' : 'errorState' ,
85
86
'[attr.aria-required]' : 'required.toString()' ,
86
- '(blur)' : '_focusChanged(false)' ,
87
- '(focus)' : '_focusChanged(true)' ,
88
- '(input)' : '_onInput()' ,
89
87
} ,
90
88
providers : [ { provide : MatFormFieldControl , useExisting : MatInput } ] ,
91
89
} )
@@ -314,14 +312,28 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
314
312
this . _elementRef . nativeElement . focus ( options ) ;
315
313
}
316
314
315
+ // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
316
+ // In Ivy the `host` bindings will be merged when this class is extended, whereas in
317
+ // ViewEngine they're overwritten.
318
+ // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
317
319
/** Callback for the cases where the focused state of the input changes. */
320
+ // tslint:disable:no-host-decorator-in-concrete
321
+ @HostListener ( 'focus' , [ 'true' ] )
322
+ @HostListener ( 'blur' , [ 'false' ] )
323
+ // tslint:enable:no-host-decorator-in-concrete
318
324
_focusChanged ( isFocused : boolean ) {
319
325
if ( isFocused !== this . focused && ( ! this . readonly || ! isFocused ) ) {
320
326
this . focused = isFocused ;
321
327
this . stateChanges . next ( ) ;
322
328
}
323
329
}
324
330
331
+ // We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
332
+ // In Ivy the `host` bindings will be merged when this class is extended, whereas in
333
+ // ViewEngine they're overwritten.
334
+ // TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
335
+ // tslint:disable-next-line:no-host-decorator-in-concrete
336
+ @HostListener ( 'input' )
325
337
_onInput ( ) {
326
338
// This is a noop function and is used to let Angular know whenever the value changes.
327
339
// Angular will run a new change detection each time the `input` event has been dispatched.
0 commit comments