66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { Directive , Output , EventEmitter , ElementRef , Input } from '@angular/core' ;
9+ import {
10+ Directive ,
11+ ElementRef ,
12+ Output ,
13+ EventEmitter ,
14+ Inject ,
15+ Input ,
16+ Optional ,
17+ Renderer2 ,
18+ Self ,
19+ } from '@angular/core' ;
20+ import { FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
21+ import { Platform } from '@angular/cdk/platform' ;
1022import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1123import { ENTER } from '../core/keyboard/keycodes' ;
1224import { MdChipList } from './chip-list' ;
25+ import { MdInput } from '../input/input' ;
26+ import {
27+ ErrorOptions ,
28+ MD_ERROR_GLOBAL_OPTIONS
29+ } from '../core/error/error-options' ;
1330
1431export interface MdChipInputEvent {
1532 input : HTMLInputElement ;
1633 value : string ;
1734}
1835
36+ /**
37+ * Directive that adds chip-specific behaviors to an input element inside <md-form-field>.
38+ * May be placed inside or outside of an <md-chip-list>.
39+ */
1940@Directive ( {
2041 selector : 'input[mdChipInputFor], input[matChipInputFor]' ,
2142 host : {
22- 'class' : 'mat-chip-input' ,
43+ 'class' : 'mat-chip-input mat-input-element ' ,
2344 '(keydown)' : '_keydown($event)' ,
24- '(blur)' : '_blur()'
45+ '(blur)' : '_blur()' ,
46+ '(focus)' : '_focus()' ,
2547 }
2648} )
27- export class MdChipInput {
49+ export class MdChipInput extends MdInput {
2850
2951 _chipList : MdChipList ;
3052
@@ -33,7 +55,7 @@ export class MdChipInput {
3355 set chipList ( value : MdChipList ) {
3456 if ( value ) {
3557 this . _chipList = value ;
36- this . _chipList . registerInput ( this . _inputElement ) ;
58+ this . _chipList . registerInput ( this ) ;
3759 }
3860 }
3961
@@ -71,7 +93,15 @@ export class MdChipInput {
7193 /** The native input element to which this directive is attached. */
7294 protected _inputElement : HTMLInputElement ;
7395
74- constructor ( protected _elementRef : ElementRef ) {
96+ constructor ( protected _elementRef : ElementRef ,
97+ protected _renderer : Renderer2 ,
98+ protected _platform : Platform ,
99+ @Optional ( ) @Self ( ) public ngControl : NgControl ,
100+ @Optional ( ) protected _parentForm : NgForm ,
101+ @Optional ( ) protected _parentFormGroup : FormGroupDirective ,
102+ @Optional ( ) @Inject ( MD_ERROR_GLOBAL_OPTIONS ) errorOptions : ErrorOptions ) {
103+ super ( _elementRef , _renderer , _platform , ngControl , _parentForm ,
104+ _parentFormGroup , errorOptions ) ;
75105 this . _inputElement = this . _elementRef . nativeElement as HTMLInputElement ;
76106 }
77107
@@ -85,6 +115,17 @@ export class MdChipInput {
85115 if ( this . addOnBlur ) {
86116 this . _emitChipEnd ( ) ;
87117 }
118+ super . _focusChanged ( false ) ;
119+ // Blur the chip list if it is not focused
120+ if ( ! this . _chipList . focused ) {
121+ this . _chipList . _blur ( ) ;
122+ }
123+ this . _chipList . stateChanges . next ( ) ;
124+ }
125+
126+ _focus ( ) {
127+ super . _focusChanged ( true ) ;
128+ this . _chipList . stateChanges . next ( ) ;
88129 }
89130
90131 /** Checks to see if the (chipEnd) event needs to be emitted. */
0 commit comments