@@ -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,40 @@ 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): this also a `trigger` parameter that the chip isn't
71
+ // handling yet. Consider passing it along once MDC start using it.
72
+ notifyInteraction : ( ) => {
73
+ // this._chip._notifyInteraction();
74
+ } ,
75
+
76
+ // TODO(crisbeto): this also a `key` parameter that the chip isn't
77
+ // handling yet. Consider passing it along once MDC start using it.
78
+ notifyNavigation : ( ) => {
79
+ // this._chip._notifyNavigation();
80
+ }
81
+ } ;
82
+
83
+ constructor (
84
+ public _elementRef : ElementRef ,
85
+ // TODO(crisbeto): currently the chip needs a reference to the trailing icon for the deprecated
86
+ // `setTrailingActionAttr` method. Until the method is removed, we can't use the chip here,
87
+ // because it causes a circular import.
88
+ // private _chip: MatChip
89
+ ) {
90
+ this . _foundation = new MDCChipTrailingActionFoundation ( this . _adapter ) ;
91
+ }
92
+
93
+ ngOnDestroy ( ) {
94
+ this . _foundation . destroy ( ) ;
95
+ }
62
96
63
97
focus ( ) {
64
98
this . _elementRef . nativeElement . focus ( ) ;
@@ -75,8 +109,8 @@ export class MatChipTrailingIcon {
75
109
* @docs -private
76
110
*/
77
111
class MatChipRemoveBase extends MatChipTrailingIcon {
78
- constructor ( _elementRef : ElementRef ) {
79
- super ( _elementRef ) ;
112
+ constructor ( elementRef : ElementRef ) {
113
+ super ( elementRef ) ;
80
114
}
81
115
}
82
116
0 commit comments