@@ -33,10 +33,6 @@ import {MDCChipFoundation} from './foundation';
33
33
import { MDCChipInteractionEventDetail , MDCChipNavigationEventDetail , MDCChipRemovalEventDetail ,
34
34
MDCChipSelectionEventDetail } from './types' ;
35
35
36
- type InteractionType = 'click' | 'keydown' ;
37
-
38
- const INTERACTION_EVENTS : InteractionType [ ] = [ 'click' , 'keydown' ] ;
39
-
40
36
export type MDCChipFactory = ( el : Element , foundation ?: MDCChipFoundation ) => MDCChip ;
41
37
42
38
export class MDCChip extends MDCComponent < MDCChipFoundation > implements MDCRippleCapableSurface {
@@ -84,20 +80,17 @@ export class MDCChip extends MDCComponent<MDCChipFoundation> implements MDCRippl
84
80
root_ ! : HTMLElement ; // assigned in MDCComponent constructor
85
81
86
82
private leadingIcon_ ! : Element | null ; // assigned in initialize()
87
- private trailingIcon_ ! : Element | null ; // assigned in initialize()
88
83
private checkmark_ ! : Element | null ; // assigned in initialize()
89
84
private ripple_ ! : MDCRipple ; // assigned in initialize()
90
85
private primaryAction_ ! : Element | null ; // assigned in initialize()
91
86
private trailingAction_ ! : Element | null ; // assigned in initialize()
92
87
93
- private handleInteraction_ ! : SpecificEventListener < InteractionType > ; // assigned in initialSyncWithDOM()
88
+ private handleClick_ ! : SpecificEventListener < 'click' > ; // assigned in initialSyncWithDOM()
94
89
private handleTransitionEnd_ ! : SpecificEventListener < 'transitionend' > ; // assigned in initialSyncWithDOM()
95
- private handleTrailingIconInteraction_ ! : SpecificEventListener < InteractionType > ; // assigned in initialSyncWithDOM()
96
90
private handleKeydown_ ! : SpecificEventListener < 'keydown' > ; // assigned in initialSyncWithDOM()
97
91
98
92
initialize ( rippleFactory : MDCRippleFactory = ( el , foundation ) => new MDCRipple ( el , foundation ) ) {
99
93
this . leadingIcon_ = this . root_ . querySelector ( strings . LEADING_ICON_SELECTOR ) ;
100
- this . trailingIcon_ = this . root_ . querySelector ( strings . TRAILING_ICON_SELECTOR ) ;
101
94
this . checkmark_ = this . root_ . querySelector ( strings . CHECKMARK_SELECTOR ) ;
102
95
this . primaryAction_ = this . root_ . querySelector ( strings . PRIMARY_ACTION_SELECTOR ) ;
103
96
this . trailingAction_ = this . root_ . querySelector ( strings . TRAILING_ACTION_SELECTOR ) ;
@@ -112,40 +105,21 @@ export class MDCChip extends MDCComponent<MDCChipFoundation> implements MDCRippl
112
105
}
113
106
114
107
initialSyncWithDOM ( ) {
115
- this . handleInteraction_ = ( evt : MouseEvent | KeyboardEvent ) => this . foundation_ . handleInteraction ( evt ) ;
108
+ this . handleClick_ = ( evt : MouseEvent ) => this . foundation_ . handleClick ( evt ) ;
116
109
this . handleTransitionEnd_ = ( evt : TransitionEvent ) => this . foundation_ . handleTransitionEnd ( evt ) ;
117
- this . handleTrailingIconInteraction_ = ( evt : MouseEvent | KeyboardEvent ) =>
118
- this . foundation_ . handleTrailingIconInteraction ( evt ) ;
119
110
this . handleKeydown_ = ( evt : KeyboardEvent ) => this . foundation_ . handleKeydown ( evt ) ;
120
111
121
- INTERACTION_EVENTS . forEach ( ( evtType ) => {
122
- this . listen ( evtType , this . handleInteraction_ ) ;
123
- } ) ;
112
+ this . listen ( 'click' , this . handleClick_ ) ;
124
113
this . listen ( 'transitionend' , this . handleTransitionEnd_ ) ;
125
114
this . listen ( 'keydown' , this . handleKeydown_ ) ;
126
-
127
- if ( this . trailingIcon_ ) {
128
- INTERACTION_EVENTS . forEach ( ( evtType ) => {
129
- this . trailingIcon_ ! . addEventListener ( evtType , this . handleTrailingIconInteraction_ as EventListener ) ;
130
- } ) ;
131
- }
132
115
}
133
116
134
117
destroy ( ) {
135
118
this . ripple_ . destroy ( ) ;
136
-
137
- INTERACTION_EVENTS . forEach ( ( evtType ) => {
138
- this . unlisten ( evtType , this . handleInteraction_ ) ;
139
- } ) ;
119
+ this . unlisten ( 'click' , this . handleClick_ ) ;
140
120
this . unlisten ( 'transitionend' , this . handleTransitionEnd_ ) ;
141
121
this . unlisten ( 'keydown' , this . handleKeydown_ ) ;
142
122
143
- if ( this . trailingIcon_ ) {
144
- INTERACTION_EVENTS . forEach ( ( evtType ) => {
145
- this . trailingIcon_ ! . removeEventListener ( evtType , this . handleTrailingIconInteraction_ as EventListener ) ;
146
- } ) ;
147
- }
148
-
149
123
super . destroy ( ) ;
150
124
}
151
125
0 commit comments