@@ -11,6 +11,7 @@ import {
11
11
ChangeDetectorRef ,
12
12
Directive ,
13
13
ElementRef ,
14
+ OnDestroy ,
14
15
} from '@angular/core' ;
15
16
import {
16
17
CanDisable ,
@@ -20,6 +21,7 @@ import {
20
21
mixinDisabled ,
21
22
mixinTabIndex ,
22
23
} from '@angular/material/core' ;
24
+ import { MDCChipTrailingActionAdapter , MDCChipTrailingActionFoundation } from '@material/chips' ;
23
25
import { Subject } from 'rxjs' ;
24
26
25
27
@@ -57,8 +59,42 @@ export class MatChipAvatar {
57
59
'aria-hidden' : 'true' ,
58
60
}
59
61
} )
60
- export class MatChipTrailingIcon {
61
- constructor ( public _elementRef : ElementRef ) { }
62
+ export class MatChipTrailingIcon implements OnDestroy {
63
+ private _foundation : MDCChipTrailingActionFoundation ;
64
+ private _adapter : MDCChipTrailingActionAdapter = {
65
+ focus : ( ) => this . _elementRef . nativeElement . focus ( ) ,
66
+ getAttribute : ( name : string ) => this . _elementRef . nativeElement . getAttribute ( name ) ,
67
+ setAttribute : ( name : string , value : string ) => {
68
+ this . _elementRef . nativeElement . setAttribute ( name , value ) ;
69
+ } ,
70
+ // TODO(crisbeto): there's also a `trigger` parameter that the chip isn't
71
+ // handling yet. Consider passing it along once MDC start using it.
72
+ notifyInteraction : ( ) => {
73
+ // TODO(crisbeto): uncomment this code once we've inverted the dependency on `MatChip`.
74
+ // this._chip._notifyInteraction();
75
+ } ,
76
+
77
+ // TODO(crisbeto): there's also a `key` parameter that the chip isn't
78
+ // handling yet. Consider passing it along once MDC start using it.
79
+ notifyNavigation : ( ) => {
80
+ // TODO(crisbeto): uncomment this code once we've inverted the dependency on `MatChip`.
81
+ // this._chip._notifyNavigation();
82
+ }
83
+ } ;
84
+
85
+ constructor (
86
+ public _elementRef : ElementRef ,
87
+ // TODO(crisbeto): currently the chip needs a reference to the trailing icon for the deprecated
88
+ // `setTrailingActionAttr` method. Until the method is removed, we can't use the chip here,
89
+ // because it causes a circular import.
90
+ // private _chip: MatChip
91
+ ) {
92
+ this . _foundation = new MDCChipTrailingActionFoundation ( this . _adapter ) ;
93
+ }
94
+
95
+ ngOnDestroy ( ) {
96
+ this . _foundation . destroy ( ) ;
97
+ }
62
98
63
99
focus ( ) {
64
100
this . _elementRef . nativeElement . focus ( ) ;
@@ -75,8 +111,8 @@ export class MatChipTrailingIcon {
75
111
* @docs -private
76
112
*/
77
113
class MatChipRemoveBase extends MatChipTrailingIcon {
78
- constructor ( _elementRef : ElementRef ) {
79
- super ( _elementRef ) ;
114
+ constructor ( elementRef : ElementRef ) {
115
+ super ( elementRef ) ;
80
116
}
81
117
}
82
118
0 commit comments