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

Commit

Permalink
fix(chips): Should use foundation handleChipRemoval method (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
trimox authored Aug 8, 2018
1 parent 07a1ded commit c930820
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
QueryList,
ViewEncapsulation
} from '@angular/core';
import { defer, merge, Observable, Subject } from 'rxjs';
import { defer, merge, Observable, Subject, Subscription } from 'rxjs';
import { startWith, switchMap, take, takeUntil } from 'rxjs/operators';

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

/** Subscription to remove changes in chips. */
private _chipRemoveSubscription: Subscription | null;

/**
* Indicates that the chips in the set are choice chips, which allow a single selection from a set of options.
*/
Expand Down Expand Up @@ -81,6 +84,11 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {

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

/** Combined stream of all of the child chips' remove change events. */
get chipRemoveChanges(): Observable<MdcChipInteractionEvent> {
return merge(...this.chips.map(chip => chip.removed));
}

/** Combined stream of all of the chip change events. */
readonly chipSelectionChanges: Observable<MdcChipInteractionEvent> = defer(() => {
if (this.chips) {
Expand Down Expand Up @@ -122,6 +130,10 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
this._foundation.handleChipInteraction(event);
});

this._chipRemoveSubscription = this.chipRemoveChanges.subscribe((event: MdcChipInteractionEvent) => {
this._foundation.handleChipRemoval(event);
});

this.chips.changes.pipe(startWith(null), takeUntil(this._destroy)).subscribe(() => {
Promise.resolve().then(() => {
this.chips.forEach(chip => {
Expand Down

0 comments on commit c930820

Please sign in to comment.