@@ -42,16 +42,10 @@ import {
4242import { FocusMonitor } from '@angular/cdk/a11y' ;
4343import { Subject } from 'rxjs' ;
4444import { take } from 'rxjs/operators' ;
45- import {
46- MatChipAvatar ,
47- MatChipTrailingIcon ,
48- MatChipRemove ,
49- MAT_CHIP_AVATAR ,
50- MAT_CHIP_TRAILING_ICON ,
51- MAT_CHIP_REMOVE ,
52- } from './chip-icons' ;
45+ import { MatChipAvatar , MatChipTrailingIcon , MatChipRemove } from './chip-icons' ;
5346import { MatChipAction } from './chip-action' ;
54- import { BACKSPACE , DELETE , ENTER , SPACE } from '@angular/cdk/keycodes' ;
47+ import { BACKSPACE , DELETE } from '@angular/cdk/keycodes' ;
48+ import { MAT_CHIP , MAT_CHIP_AVATAR , MAT_CHIP_REMOVE , MAT_CHIP_TRAILING_ICON } from './tokens' ;
5549
5650let uid = 0 ;
5751
@@ -102,11 +96,11 @@ const _MatChipMixinBase = mixinTabIndex(mixinColor(mixinDisableRipple(MatChipBas
10296 '[attr.role]' : 'role' ,
10397 '[attr.tabindex]' : 'role ? tabIndex : null' ,
10498 '[attr.aria-label]' : 'ariaLabel' ,
105- '(click)' : '_handleClick($event)' ,
10699 '(keydown)' : '_handleKeydown($event)' ,
107100 } ,
108101 encapsulation : ViewEncapsulation . None ,
109102 changeDetection : ChangeDetectionStrategy . OnPush ,
103+ providers : [ { provide : MAT_CHIP , useExisting : MatChip } ] ,
110104} )
111105export class MatChip
112106 extends _MatChipMixinBase
@@ -289,23 +283,9 @@ export class MatChip
289283 return ! ! ( this . trailingIcon || this . removeIcon ) ;
290284 }
291285
292- /** Handles click events on the chip. */
293- _handleClick ( event : MouseEvent ) {
294- const action = this . _getSourceAction ( event . target as Node ) ;
295-
296- if ( action ) {
297- this . _handleClickLikeInteraction ( event , action ) ;
298- }
299- }
300-
301286 /** Handles keyboard events on the chip. */
302287 _handleKeydown ( event : KeyboardEvent ) {
303- const action = this . _getSourceAction ( event . target as Node ) ;
304- const keyCode = event . keyCode ;
305-
306- if ( action && ( keyCode === ENTER || keyCode === SPACE ) ) {
307- this . _handleClickLikeInteraction ( event , action ) ;
308- } else if ( keyCode === BACKSPACE || keyCode === DELETE ) {
288+ if ( event . keyCode === BACKSPACE || event . keyCode === DELETE ) {
309289 event . preventDefault ( ) ;
310290 this . remove ( ) ;
311291 }
@@ -353,24 +333,10 @@ export class MatChip
353333 }
354334
355335 /** Handles interactions with the primary action of the chip. */
356- protected _handlePrimaryActionInteraction ( ) {
336+ _handlePrimaryActionInteraction ( ) {
357337 // Empty here, but is overwritten in child classes.
358338 }
359339
360- /** Handles clicks or enter/space presses on a specific action. */
361- private _handleClickLikeInteraction ( event : Event , action : MatChipAction ) {
362- if ( action . isInteractive && ! action . disabled ) {
363- if ( action === this . removeIcon ) {
364- event . preventDefault ( ) ;
365- event . stopPropagation ( ) ;
366- this . remove ( ) ;
367- } else if ( action === this . primaryAction ) {
368- event . preventDefault ( ) ;
369- this . _handlePrimaryActionInteraction ( ) ;
370- }
371- }
372- }
373-
374340 /** Starts the focus monitoring process on the chip. */
375341 private _monitorFocus ( ) {
376342 this . _focusMonitor . monitor ( this . _elementRef , true ) . subscribe ( origin => {
0 commit comments