Skip to content

Commit

Permalink
fix(chips): remove circular dependency between chip-list and chip-inp…
Browse files Browse the repository at this point in the history
…ut (#13994)

This change is necessary because some Google-internal infrastructure has
started encountering errors because of this particular circular dep.
  • Loading branch information
jelbourn committed Nov 6, 2018
1 parent 4e50d4a commit 3da858d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/lib/chips/chip-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {Directive, ElementRef, EventEmitter, Input, Output, Inject, OnChanges} from '@angular/core';
import {MatChipList} from './chip-list';
import {Directive, ElementRef, EventEmitter, Inject, Input, OnChanges, Output} from '@angular/core';
import {MAT_CHIPS_DEFAULT_OPTIONS, MatChipsDefaultOptions} from './chip-default-options';
import {MatChipList} from './chip-list';
import {MatChipTextControl} from './chip-text-control';


/** Represents an input event on a `matChipInput`. */
Expand Down Expand Up @@ -43,7 +44,7 @@ let nextUniqueId = 0;
'[attr.aria-invalid]': '_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null',
}
})
export class MatChipInput implements OnChanges {
export class MatChipInput implements MatChipTextControl, OnChanges {
/** Whether the control is focused. */
focused: boolean = false;
_chipList: MatChipList;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {MatFormFieldControl} from '@angular/material/form-field';
import {merge, Observable, Subject, Subscription} from 'rxjs';
import {startWith, takeUntil} from 'rxjs/operators';
import {MatChip, MatChipEvent, MatChipSelectionChange} from './chip';
import {MatChipInput} from './chip-input';
import {MatChipTextControl} from './chip-text-control';


// Boilerplate for applying mixins to MatChipList.
Expand Down Expand Up @@ -131,7 +131,7 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
private _chipRemoveSubscription: Subscription | null;

/** The chip input to add more chips */
protected _chipInput: MatChipInput;
protected _chipInput: MatChipTextControl;

/** Uid of the chip list */
_uid: string = `mat-chip-list-${nextUniqueId++}`;
Expand Down Expand Up @@ -400,7 +400,7 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo


/** Associates an HTML input element with this chip list. */
registerInput(inputElement: MatChipInput): void {
registerInput(inputElement: MatChipTextControl): void {
this._chipInput = inputElement;
}

Expand Down
26 changes: 26 additions & 0 deletions src/lib/chips/chip-text-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/


/** Interface for a text control that is used to drive interaction with a mat-chip-list. */
export interface MatChipTextControl {
/** Unique identifier for the text control. */
id: string;

/** The text control's placeholder text. */
placeholder: string;

/** Whether the text control has browser focus. */
focused: boolean;

/** Whether the text control is empty. */
empty: boolean;

/** Focuses the text control. */
focus(): void;
}

0 comments on commit 3da858d

Please sign in to comment.