Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit c930820

Browse files
authored
fix(chips): Should use foundation handleChipRemoval method (#1185)
1 parent 07a1ded commit c930820

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/chips/chip-set.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
QueryList,
1414
ViewEncapsulation
1515
} from '@angular/core';
16-
import { defer, merge, Observable, Subject } from 'rxjs';
16+
import { defer, merge, Observable, Subject, Subscription } from 'rxjs';
1717
import { startWith, switchMap, take, takeUntil } from 'rxjs/operators';
1818

1919
import { toBoolean, EventRegistry } from '@angular-mdc/web/common';
@@ -38,6 +38,9 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
3838
/** Emits whenever the component is destroyed. */
3939
private _destroy = new Subject<void>();
4040

41+
/** Subscription to remove changes in chips. */
42+
private _chipRemoveSubscription: Subscription | null;
43+
4144
/**
4245
* Indicates that the chips in the set are choice chips, which allow a single selection from a set of options.
4346
*/
@@ -81,6 +84,11 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
8184

8285
@ContentChildren(MdcChip) chips: QueryList<MdcChip>;
8386

87+
/** Combined stream of all of the child chips' remove change events. */
88+
get chipRemoveChanges(): Observable<MdcChipInteractionEvent> {
89+
return merge(...this.chips.map(chip => chip.removed));
90+
}
91+
8492
/** Combined stream of all of the chip change events. */
8593
readonly chipSelectionChanges: Observable<MdcChipInteractionEvent> = defer(() => {
8694
if (this.chips) {
@@ -122,6 +130,10 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
122130
this._foundation.handleChipInteraction(event);
123131
});
124132

133+
this._chipRemoveSubscription = this.chipRemoveChanges.subscribe((event: MdcChipInteractionEvent) => {
134+
this._foundation.handleChipRemoval(event);
135+
});
136+
125137
this.chips.changes.pipe(startWith(null), takeUntil(this._destroy)).subscribe(() => {
126138
Promise.resolve().then(() => {
127139
this.chips.forEach(chip => {

0 commit comments

Comments
 (0)