Skip to content

Commit 6c741c4

Browse files
authored
fix(chips): remove circular dependency between chip-list and chip-input (#13994)
This change is necessary because some Google-internal infrastructure has started encountering errors because of this particular circular dep.
1 parent 12c15ba commit 6c741c4

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/lib/chips/chip-input.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

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

1415

1516
/** Represents an input event on a `matChipInput`. */
@@ -43,7 +44,7 @@ let nextUniqueId = 0;
4344
'[attr.aria-invalid]': '_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null',
4445
}
4546
})
46-
export class MatChipInput implements OnChanges {
47+
export class MatChipInput implements MatChipTextControl, OnChanges {
4748
/** Whether the control is focused. */
4849
focused: boolean = false;
4950
_chipList: MatChipList;

src/lib/chips/chip-list.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {MatFormFieldControl} from '@angular/material/form-field';
4040
import {merge, Observable, Subject, Subscription} from 'rxjs';
4141
import {startWith, takeUntil} from 'rxjs/operators';
4242
import {MatChip, MatChipEvent, MatChipSelectionChange} from './chip';
43-
import {MatChipInput} from './chip-input';
43+
import {MatChipTextControl} from './chip-text-control';
4444

4545

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

133133
/** The chip input to add more chips */
134-
protected _chipInput: MatChipInput;
134+
protected _chipInput: MatChipTextControl;
135135

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

401401

402402
/** Associates an HTML input element with this chip list. */
403-
registerInput(inputElement: MatChipInput): void {
403+
registerInput(inputElement: MatChipTextControl): void {
404404
this._chipInput = inputElement;
405405
}
406406

src/lib/chips/chip-text-control.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
10+
/** Interface for a text control that is used to drive interaction with a mat-chip-list. */
11+
export interface MatChipTextControl {
12+
/** Unique identifier for the text control. */
13+
id: string;
14+
15+
/** The text control's placeholder text. */
16+
placeholder: string;
17+
18+
/** Whether the text control has browser focus. */
19+
focused: boolean;
20+
21+
/** Whether the text control is empty. */
22+
empty: boolean;
23+
24+
/** Focuses the text control. */
25+
focus(): void;
26+
}

0 commit comments

Comments
 (0)