Skip to content

Commit 90fe256

Browse files
Ripple working, style margins fixed
1 parent 7a0882b commit 90fe256

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="mdc-chip" [ngClass]="_classes" tabindex="0">
1+
<div #wrapper class="mdc-chip" [ngClass]="_classes" tabindex="0">
22
<div class="mdc-chip__text"><ng-content></ng-content></div>
33
</div>
44

src/material-experimental/mdc-chips/chip-cell.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {AfterContentInit, AfterViewInit, Component, ChangeDetectorRef, ContentChild, Directive, ElementRef, EventEmitter, Input, OnDestroy, Output} from '@angular/core';
9+
import {Platform} from '@angular/cdk/platform';
10+
import {AfterContentInit, AfterViewInit, Component, ChangeDetectorRef, ContentChild, Directive, ElementRef, EventEmitter, Input, NgZone, OnDestroy, Output, ViewChild} from '@angular/core';
11+
import {RippleRenderer, RippleTarget} from '@angular/material/core';
1012
import {MDCChipAdapter, MDCChipFoundation} from '@material/chips';
1113
import {Subject} from 'rxjs';
1214
import {takeUntil} from 'rxjs/operators';
1315

1416
let uid = 0;
1517

18+
const rippleTarget: RippleTarget = {
19+
rippleConfig: {
20+
animation: {
21+
// TODO(mmalerba): Use the MDC constants once they are exported separately from the
22+
// foundation. Grabbing them off the foundation prevents the foundation class from being
23+
// tree-shaken. There is an open PR for this:
24+
// https://github.com/material-components/material-components-web/pull/4593
25+
enterDuration: 225 /* MDCRippleFoundation.numbers.DEACTIVATION_TIMEOUT_MS */,
26+
exitDuration: 150 /* MDCRippleFoundation.numbers.FG_DEACTIVATION_MS */,
27+
},
28+
},
29+
rippleDisabled: false
30+
};
31+
1632
/**
1733
* Dummy directive to add CSS class to chip leading icon.
1834
* @docs-private
@@ -113,12 +129,16 @@ export class MatChipCell implements AfterContentInit, AfterViewInit, OnDestroy {
113129
/** Subject that emits when the component has been destroyed. */
114130
private _destroyed = new Subject<void>();
115131

132+
/** The ripple renderer for this chip. */
133+
private _rippleRenderer: RippleRenderer;
134+
116135
/** The chip's leading icon. */
117136
@ContentChild(MatChipAvatar, {static: false}) leadingIcon: MatChipAvatar;
118137

119138
/** The chip's trailing icon. */
120139
@ContentChild(MatChipTrailingIcon, {static: false}) trailingIcon: MatChipTrailingIcon;
121140

141+
@ViewChild('wrapper') _wrapper!: ElementRef;
122142
/**
123143
* Implementation of the MDC chip adapter interface.
124144
* These methods are called by the chip foundation.
@@ -149,7 +169,9 @@ export class MatChipCell implements AfterContentInit, AfterViewInit, OnDestroy {
149169

150170
constructor(
151171
private _changeDetectorRef: ChangeDetectorRef,
152-
private _elementRef: ElementRef) {
172+
readonly _elementRef: ElementRef,
173+
private _platform: Platform,
174+
private _ngZone: NgZone) {
153175
this._chipFoundation = new MDCChipFoundation(this._chipAdapter);
154176
}
155177

@@ -162,6 +184,7 @@ export class MatChipCell implements AfterContentInit, AfterViewInit, OnDestroy {
162184
}
163185

164186
ngAfterViewInit() {
187+
this._initRipple();
165188
this._chipFoundation.init();
166189
}
167190

@@ -185,5 +208,12 @@ export class MatChipCell implements AfterContentInit, AfterViewInit, OnDestroy {
185208
this._classes[cssClass] = active;
186209
this._changeDetectorRef.markForCheck();
187210
}
211+
212+
/** Initializes the ripple renderer. */
213+
private _initRipple() {
214+
this._rippleRenderer =
215+
new RippleRenderer(rippleTarget, this._ngZone, this._wrapper, this._platform);
216+
this._rippleRenderer.setupTriggerEvents(this._wrapper.nativeElement);
217+
}
188218
}
189219

src/material-experimental/mdc-chips/chips.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
@import '../mdc-helpers/mdc-helpers';
33

44
@include mdc-chip-without-ripple($query: $mat-base-styles-query);
5-
@include mdc-chip-core-styles($query: $mat-base-styles-query);
5+
@include mdc-chip-set-core-styles($query: $mat-base-styles-query);

0 commit comments

Comments
 (0)