@@ -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,8 @@ import {
20
21
mixinDisabled ,
21
22
mixinTabIndex ,
22
23
} from '@angular/material/core' ;
24
+ import { MDCChipTrailingActionAdapter , MDCChipTrailingActionFoundation } from '@material/chips' ;
25
+ import { MatChip } from './chip' ;
23
26
import { Subject } from 'rxjs' ;
24
27
25
28
@@ -57,8 +60,36 @@ export class MatChipAvatar {
57
60
'aria-hidden' : 'true' ,
58
61
}
59
62
} )
60
- export class MatChipTrailingIcon {
61
- constructor ( public _elementRef : ElementRef ) { }
63
+ export class MatChipTrailingIcon implements OnDestroy {
64
+ private _foundation : MDCChipTrailingActionFoundation ;
65
+ private _adapter : MDCChipTrailingActionAdapter = {
66
+ focus : ( ) => this . _elementRef . nativeElement . focus ( ) ,
67
+ getAttribute : ( name : string ) => this . _elementRef . nativeElement . getAttribute ( name ) ,
68
+ setAttribute : ( name : string , value : string ) => {
69
+ this . _elementRef . nativeElement . setAttribute ( name , value ) ;
70
+ } ,
71
+ // TODO(crisbeto): this also a `trigger` parameter that the chip isn't
72
+ // handling yet. Consider passing it along once MDC start using it.
73
+ notifyInteraction : ( ) => this . _chip . _notifyInteraction ( ) ,
74
+
75
+ // TODO(crisbeto): this also a `key` parameter that the chip isn't
76
+ // handling yet. Consider passing it along once MDC start using it.
77
+ notifyNavigation : ( ) => this . _chip . _notifyNavigation ( )
78
+ } ;
79
+
80
+ constructor ( public _elementRef : ElementRef , private _chip : MatChip ) {
81
+ this . _foundation = new MDCChipTrailingActionFoundation ( this . _adapter ) ;
82
+
83
+ // TODO(crisbeto): for the time being we need to assign the trailing icon like this in order
84
+ // to avoid circular references, because the chip foundation still depends on it for the
85
+ // `setTrailingActionAttr` method. Once that method is removed in favor of the trailing
86
+ // action foundation, we can remove this call.
87
+ _chip . trailingIcon = this ;
88
+ }
89
+
90
+ ngOnDestroy ( ) {
91
+ this . _foundation . destroy ( ) ;
92
+ }
62
93
63
94
focus ( ) {
64
95
this . _elementRef . nativeElement . focus ( ) ;
@@ -75,8 +106,8 @@ export class MatChipTrailingIcon {
75
106
* @docs -private
76
107
*/
77
108
class MatChipRemoveBase extends MatChipTrailingIcon {
78
- constructor ( _elementRef : ElementRef ) {
79
- super ( _elementRef ) ;
109
+ constructor ( elementRef : ElementRef , chip : MatChip ) {
110
+ super ( elementRef , chip ) ;
80
111
}
81
112
}
82
113
@@ -123,8 +154,8 @@ export class MatChipRemove extends _MatChipRemoveMixinBase implements CanDisable
123
154
*/
124
155
interaction : Subject < MouseEvent | KeyboardEvent > = new Subject < MouseEvent | KeyboardEvent > ( ) ;
125
156
126
- constructor ( elementRef : ElementRef ) {
127
- super ( elementRef ) ;
157
+ constructor ( elementRef : ElementRef , chip : MatChip ) {
158
+ super ( elementRef , chip ) ;
128
159
129
160
if ( elementRef . nativeElement . nodeName === 'BUTTON' ) {
130
161
elementRef . nativeElement . setAttribute ( 'type' , 'button' ) ;
0 commit comments