6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import { DOCUMENT } from '@angular/common' ;
9
10
import { FocusableOption } from '@angular/cdk/a11y' ;
10
11
import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
12
import { BACKSPACE , DELETE , SPACE } from '@angular/cdk/keycodes' ;
@@ -105,7 +106,7 @@ export class MatChipTrailingIcon {}
105
106
inputs : [ 'color' , 'disabled' , 'disableRipple' , 'tabIndex' ] ,
106
107
exportAs : 'matChip' ,
107
108
host : {
108
- 'class' : 'mat-chip' ,
109
+ 'class' : 'mat-chip mat-focus-indicator ' ,
109
110
'[attr.tabindex]' : 'disabled ? null : tabIndex' ,
110
111
'role' : 'option' ,
111
112
'[class.mat-chip-selected]' : 'selected' ,
@@ -128,6 +129,13 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
128
129
/** Reference to the RippleRenderer for the chip. */
129
130
private _chipRipple : RippleRenderer ;
130
131
132
+ /**
133
+ * Reference to the element that acts as the chip's ripple target. This element is
134
+ * dynamically added as a child node of the chip. The chip itself cannot be used as the
135
+ * ripple target because it must be the host of the focus indicator.
136
+ */
137
+ private _chipRippleTarget : HTMLElement ;
138
+
131
139
/**
132
140
* Ripple configuration for ripples that are launched on pointer down. The ripple config
133
141
* is set to the global ripple options since we don't have any configurable options for
@@ -244,13 +252,22 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
244
252
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
245
253
// @breaking -change 9.0.0 `_changeDetectorRef` parameter to become required.
246
254
private _changeDetectorRef ?: ChangeDetectorRef ,
247
- @Attribute ( 'tabindex' ) tabIndex ?: string ) {
255
+ @Attribute ( 'tabindex' ) tabIndex ?: string ,
256
+ // @breaking -change 11.0.0 `_document` parameter to become required.
257
+ @Optional ( ) @Inject ( DOCUMENT ) _document ?: any ) {
248
258
super ( _elementRef ) ;
249
259
250
260
this . _addHostClassName ( ) ;
251
261
252
- this . _chipRipple = new RippleRenderer ( this , _ngZone , _elementRef , platform ) ;
262
+ // Dynamically create the ripple target, append it within the chip, and use it as the
263
+ // chip's ripple target. Adding the class '.mat-chip-ripple' ensures that it will have
264
+ // the proper styles.
265
+ this . _chipRippleTarget = ( _document || document ) . createElement ( 'div' ) ;
266
+ this . _chipRippleTarget . classList . add ( 'mat-chip-ripple' ) ;
267
+ this . _elementRef . nativeElement . appendChild ( this . _chipRippleTarget ) ;
268
+ this . _chipRipple = new RippleRenderer ( this , _ngZone , this . _chipRippleTarget , platform ) ;
253
269
this . _chipRipple . setupTriggerEvents ( _elementRef ) ;
270
+
254
271
this . rippleConfig = globalRippleOptions || { } ;
255
272
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
256
273
this . tabIndex = tabIndex != null ? ( parseInt ( tabIndex ) || - 1 ) : - 1 ;
0 commit comments