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 { coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
12
import { BACKSPACE , DELETE , SPACE } from '@angular/cdk/keycodes' ;
@@ -100,7 +101,7 @@ export class MatChipTrailingIcon {}
100
101
inputs : [ 'color' , 'disabled' , 'disableRipple' ] ,
101
102
exportAs : 'matChip' ,
102
103
host : {
103
- 'class' : 'mat-chip' ,
104
+ 'class' : 'mat-chip mat-focus-indicator ' ,
104
105
'[attr.tabindex]' : 'disabled ? null : -1' ,
105
106
'role' : 'option' ,
106
107
'[class.mat-chip-selected]' : 'selected' ,
@@ -123,6 +124,13 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
123
124
/** Reference to the RippleRenderer for the chip. */
124
125
private _chipRipple : RippleRenderer ;
125
126
127
+ /**
128
+ * Reference to the element that acts as the chip's ripple target. This element is
129
+ * dynamically added as a child node of the chip. The chip itself cannot be used as the
130
+ * ripple target because it must be the host of the focus indicator.
131
+ */
132
+ private _chipRippleTarget : HTMLElement ;
133
+
126
134
/**
127
135
* Ripple configuration for ripples that are launched on pointer down. The ripple config
128
136
* is set to the global ripple options since we don't have any configurable options for
@@ -238,13 +246,22 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
238
246
// @breaking -change 8.0.0 `animationMode` parameter to become required.
239
247
@Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
240
248
// @breaking -change 9.0.0 `_changeDetectorRef` parameter to become required.
241
- private _changeDetectorRef ?: ChangeDetectorRef ) {
249
+ private _changeDetectorRef ?: ChangeDetectorRef ,
250
+ // @breaking -change 11.0.0 `_document` parameter to become required.
251
+ @Optional ( ) @Inject ( DOCUMENT ) _document ?: any ) {
242
252
super ( _elementRef ) ;
243
253
244
254
this . _addHostClassName ( ) ;
245
255
246
- this . _chipRipple = new RippleRenderer ( this , _ngZone , _elementRef , platform ) ;
256
+ // Dynamically create the ripple target, append it within the chip, and use it as the
257
+ // chip's ripple target. Adding the class '.mat-chip-ripple' ensures that it will have
258
+ // the proper styles.
259
+ this . _chipRippleTarget = ( _document || document ) . createElement ( 'div' ) ;
260
+ this . _chipRippleTarget . classList . add ( 'mat-chip-ripple' ) ;
261
+ this . _elementRef . nativeElement . appendChild ( this . _chipRippleTarget ) ;
262
+ this . _chipRipple = new RippleRenderer ( this , _ngZone , this . _chipRippleTarget , platform ) ;
247
263
this . _chipRipple . setupTriggerEvents ( _elementRef ) ;
264
+
248
265
this . rippleConfig = globalRippleOptions || { } ;
249
266
this . _animationsDisabled = animationMode === 'NoopAnimations' ;
250
267
}
0 commit comments