Skip to content

Commit 0fdc640

Browse files
committed
refactor(material/chips): remove deprecated APIs for v13
Removes the APIs that were marked for removal in v13 in the `material/chips` module. BREAKING CHANGE: * `MatChipInputEvent.input` has been removed. Use `MatChipInputEvent.chipInput` instead. * `MatChipInputEvent.chipInput` is now a required property. * `ChipHarnessFilters.selected` has been removed. Use `MatChipOptionHarness` together with `ChipOptionHarnessFilters` instead. * `MatChipHarness.isSelected` has been removed. Use `MatChipOptionHarness.isSelected` instead. * `MatChipHarness.select` has been removed. Use `MatChipOptionHarness.select` instead. * `MatChipHarness.deselect` has been removed. Use `MatChipOptionHarness.deselect` instead. * `MatChipHarness.toggle` has been removed. Use `MatChipOptionHarness.toggle` instead. * `MatChipListHarness.selectChips` has been removed. Use `MatChipListboxHarness.selectChips` instead.
1 parent f3e8196 commit 0fdc640

File tree

10 files changed

+26
-115
lines changed

10 files changed

+26
-115
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,13 @@ import {MatChipTextControl} from './chip-text-control';
2727

2828
/** Represents an input event on a `matChipInput`. */
2929
export interface MatChipInputEvent {
30-
/**
31-
* The native `<input>` element that the event is being fired for.
32-
* @deprecated Use `MatChipInputEvent#chipInput.inputElement` instead.
33-
* @breaking-change 13.0.0 This property will be removed.
34-
*/
35-
input: HTMLInputElement;
36-
3730
/** The value of the input. */
3831
value: string;
3932

4033
/**
4134
* Reference to the chip input that emitted the event.
42-
* @breaking-change 13.0.0 This property will be made required.
4335
*/
44-
chipInput?: MatChipInput;
36+
chipInput: MatChipInput;
4537
}
4638

4739
// Increasing integer for generating unique ids.
@@ -215,7 +207,6 @@ export class MatChipInput implements MatChipTextControl, AfterContentInit, OnCha
215207

216208
if (!event || this._isSeparatorKey(event)) {
217209
this.chipEnd.emit({
218-
input: this.inputElement,
219210
value: this.inputElement.value,
220211
chipInput: this,
221212
});

src/material-experimental/mdc-chips/testing/chip-harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import {MatChipRemoveHarness} from './chip-remove-harness';
1919
export class MatChipHarness extends ContentContainerComponentHarness {
2020
static hostSelector = '.mat-mdc-basic-chip, .mat-mdc-chip';
2121

22+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
23+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
2224
/**
2325
* Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes.
2426
*/
25-
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
26-
// methods. See https://github.com/microsoft/TypeScript/issues/5863
2727
static with<T extends typeof MatChipHarness>(this: T, options: ChipHarnessFilters = {}):
2828
HarnessPredicate<InstanceType<T>> {
2929
return new HarnessPredicate(MatChipHarness, options)

src/material-experimental/mdc-chips/testing/chip-option-harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {ChipOptionHarnessFilters} from './chip-harness-filters';
1414
export class MatChipOptionHarness extends MatChipHarness {
1515
static override hostSelector = '.mat-mdc-chip-option';
1616

17+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
18+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
1719
/**
1820
* Gets a `HarnessPredicate` that can be used to search for a chip option with specific
1921
* attributes.
2022
*/
21-
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
22-
// methods. See https://github.com/microsoft/TypeScript/issues/5863
2323
static override with<T extends typeof MatChipHarness>(
2424
this: T, options: ChipOptionHarnessFilters = {}): HarnessPredicate<InstanceType<T>> {
2525
return new HarnessPredicate(MatChipOptionHarness, options)

src/material/chips/chip-input.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,13 @@ import {MatChipTextControl} from './chip-text-control';
2525

2626
/** Represents an input event on a `matChipInput`. */
2727
export interface MatChipInputEvent {
28-
/**
29-
* The native `<input>` element that the event is being fired for.
30-
* @deprecated Use `MatChipInputEvent#chipInput.inputElement` instead.
31-
* @breaking-change 13.0.0 This property will be removed.
32-
*/
33-
input: HTMLInputElement;
34-
3528
/** The value of the input. */
3629
value: string;
3730

3831
/**
3932
* Reference to the chip input that emitted the event.
40-
* @breaking-change 13.0.0 This property will be made required.
4133
*/
42-
chipInput?: MatChipInput;
34+
chipInput: MatChipInput;
4335
}
4436

4537
// Increasing integer for generating unique ids.
@@ -201,7 +193,6 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy, A
201193

202194
if (!event || this._isSeparatorKey(event)) {
203195
this.chipEnd.emit({
204-
input: this.inputElement,
205196
value: this.inputElement.value,
206197
chipInput: this,
207198
});

src/material/chips/testing/chip-harness-filters.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import {BaseHarnessFilters} from '@angular/cdk/testing';
1111
export interface ChipHarnessFilters extends BaseHarnessFilters {
1212
/** Only find instances whose text matches the given value. */
1313
text?: string | RegExp;
14-
/**
15-
* Only find chip instances whose selected state matches the given value.
16-
* @deprecated Use `MatChipOptionHarness` together with `ChipOptionHarnessFilters`.
17-
* @breaking-change 12.0.0
18-
*/
19-
selected?: boolean;
2014
}
2115

2216
/** A set of criteria that can be used to filter a list of selectable chip instances. */

src/material/chips/testing/chip-harness.ts

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export class MatChipHarness extends ContentContainerComponentHarness {
2626
* @param options Options for filtering which chip instances are considered a match.
2727
* @return a `HarnessPredicate` configured with the given options.
2828
*/
29-
static with(options: ChipHarnessFilters = {}): HarnessPredicate<MatChipHarness> {
29+
static with<T extends typeof MatChipHarness>(options: ChipHarnessFilters = {}):
30+
HarnessPredicate<InstanceType<T>> {
3031
return new HarnessPredicate(MatChipHarness, options)
31-
.addOption('text', options.text,
32-
(harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
33-
.addOption('selected', options.selected,
34-
async (harness, selected) => (await harness.isSelected()) === selected);
32+
.addOption('text', options.text, (harness, label) => {
33+
return HarnessPredicate.stringMatches(harness.getText(), label);
34+
}) as unknown as HarnessPredicate<InstanceType<T>>;
3535
}
3636

3737
/** Gets the text of the chip. */
@@ -41,51 +41,11 @@ export class MatChipHarness extends ContentContainerComponentHarness {
4141
});
4242
}
4343

44-
/**
45-
* Whether the chip is selected.
46-
* @deprecated Use `MatChipOptionHarness.isSelected` instead.
47-
* @breaking-change 12.0.0
48-
*/
49-
async isSelected(): Promise<boolean> {
50-
return (await this.host()).hasClass('mat-chip-selected');
51-
}
52-
5344
/** Whether the chip is disabled. */
5445
async isDisabled(): Promise<boolean> {
5546
return (await this.host()).hasClass('mat-chip-disabled');
5647
}
5748

58-
/**
59-
* Selects the given chip. Only applies if it's selectable.
60-
* @deprecated Use `MatChipOptionHarness.select` instead.
61-
* @breaking-change 12.0.0
62-
*/
63-
async select(): Promise<void> {
64-
if (!(await this.isSelected())) {
65-
await this.toggle();
66-
}
67-
}
68-
69-
/**
70-
* Deselects the given chip. Only applies if it's selectable.
71-
* @deprecated Use `MatChipOptionHarness.deselect` instead.
72-
* @breaking-change 12.0.0
73-
*/
74-
async deselect(): Promise<void> {
75-
if (await this.isSelected()) {
76-
await this.toggle();
77-
}
78-
}
79-
80-
/**
81-
* Toggles the selected state of the given chip. Only applies if it's selectable.
82-
* @deprecated Use `MatChipOptionHarness.toggle` instead.
83-
* @breaking-change 12.0.0
84-
*/
85-
async toggle(): Promise<void> {
86-
return (await this.host()).sendKeys(' ');
87-
}
88-
8949
/** Removes the given chip. Only applies if it's removable. */
9050
async remove(): Promise<void> {
9151
await (await this.host()).sendKeys(TestKey.DELETE);

src/material/chips/testing/chip-list-harness.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ComponentHarness, HarnessPredicate, parallel} from '@angular/cdk/testing';
9+
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
1010
import {MatChipHarness} from './chip-harness';
1111
import {MatChipInputHarness} from './chip-input-harness';
1212
import {
@@ -67,21 +67,6 @@ export class MatChipListHarness extends _MatChipListHarnessBase {
6767
return this.locatorForAll(MatChipHarness.with(filter))();
6868
}
6969

70-
/**
71-
* Selects a chip inside the chip list.
72-
* @param filter An optional filter to apply to the child chips.
73-
* All the chips matching the filter will be selected.
74-
* @deprecated Use `MatChipListboxHarness.selectChips` instead.
75-
* @breaking-change 12.0.0
76-
*/
77-
async selectChips(filter: ChipHarnessFilters = {}): Promise<void> {
78-
const chips = await this.getChips(filter);
79-
if (!chips.length) {
80-
throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`);
81-
}
82-
await parallel(() => chips.map(chip => chip.select()));
83-
}
84-
8570
/**
8671
* Gets the `MatChipInput` inside the chip list.
8772
* @param filter Optionally filters which chip input is included.

src/material/chips/testing/chip-option-harness.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@ export class MatChipOptionHarness extends MatChipHarness {
1414
/** The selector for the host element of a selectable chip instance. */
1515
static override hostSelector = '.mat-chip';
1616

17+
// Note(mmalerba): generics are used as a workaround for lack of polymorphic `this` in static
18+
// methods. See https://github.com/microsoft/TypeScript/issues/5863
1719
/**
1820
* Gets a `HarnessPredicate` that can be used to search for a `MatChipOptionHarness`
1921
* that meets certain criteria.
2022
* @param options Options for filtering which chip instances are considered a match.
2123
* @return a `HarnessPredicate` configured with the given options.
2224
*/
23-
static override with(options: ChipOptionHarnessFilters = {}):
24-
HarnessPredicate<MatChipOptionHarness> {
25+
static override with<T extends typeof MatChipHarness>(
26+
this: T, options: ChipOptionHarnessFilters = {}):
27+
HarnessPredicate<InstanceType<T>> {
2528
return new HarnessPredicate(MatChipOptionHarness, options)
2629
.addOption('text', options.text,
2730
(harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
2831
.addOption('selected', options.selected,
29-
async (harness, selected) => (await harness.isSelected()) === selected);
32+
async (harness, selected) => (await harness.isSelected()) === selected) as
33+
unknown as HarnessPredicate<InstanceType<T>>;
3034
}
3135

3236
/** Whether the chip is selected. */
33-
override async isSelected(): Promise<boolean> {
37+
async isSelected(): Promise<boolean> {
3438
return (await this.host()).hasClass('mat-chip-selected');
3539
}
3640

3741
/** Selects the given chip. Only applies if it's selectable. */
38-
override async select(): Promise<void> {
42+
async select(): Promise<void> {
3943
if (!(await this.isSelected())) {
4044
await this.toggle();
4145
}
4246
}
4347

4448
/** Deselects the given chip. Only applies if it's selectable. */
45-
override async deselect(): Promise<void> {
49+
async deselect(): Promise<void> {
4650
if (await this.isSelected()) {
4751
await this.toggle();
4852
}
4953
}
5054

5155
/** Toggles the selected state of the given chip. */
52-
override async toggle(): Promise<void> {
56+
async toggle(): Promise<void> {
5357
return (await this.host()).sendKeys(' ');
5458
}
5559
}

tools/public_api_guard/material/chips-testing.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export interface ChipAvatarHarnessFilters extends BaseHarnessFilters {
1616

1717
// @public
1818
export interface ChipHarnessFilters extends BaseHarnessFilters {
19-
// @deprecated
20-
selected?: boolean;
2119
text?: string | RegExp;
2220
}
2321

@@ -46,21 +44,13 @@ export interface ChipRemoveHarnessFilters extends BaseHarnessFilters {
4644

4745
// @public
4846
export class MatChipHarness extends ContentContainerComponentHarness {
49-
// @deprecated
50-
deselect(): Promise<void>;
5147
getAvatar(filter?: ChipAvatarHarnessFilters): Promise<MatChipAvatarHarness | null>;
5248
getRemoveButton(filter?: ChipRemoveHarnessFilters): Promise<MatChipRemoveHarness>;
5349
getText(): Promise<string>;
5450
static hostSelector: string;
5551
isDisabled(): Promise<boolean>;
56-
// @deprecated
57-
isSelected(): Promise<boolean>;
5852
remove(): Promise<void>;
59-
// @deprecated
60-
select(): Promise<void>;
61-
// @deprecated
62-
toggle(): Promise<void>;
63-
static with(options?: ChipHarnessFilters): HarnessPredicate<MatChipHarness>;
53+
static with<T extends typeof MatChipHarness>(options?: ChipHarnessFilters): HarnessPredicate<InstanceType<T>>;
6454
}
6555

6656
// @public
@@ -92,8 +82,6 @@ export class MatChipListHarness extends _MatChipListHarnessBase {
9282
getChips(filter?: ChipHarnessFilters): Promise<MatChipHarness[]>;
9383
getInput(filter?: ChipInputHarnessFilters): Promise<MatChipInputHarness>;
9484
static hostSelector: string;
95-
// @deprecated
96-
selectChips(filter?: ChipHarnessFilters): Promise<void>;
9785
static with(options?: ChipListHarnessFilters): HarnessPredicate<MatChipListHarness>;
9886
}
9987

@@ -104,7 +92,7 @@ export class MatChipOptionHarness extends MatChipHarness {
10492
isSelected(): Promise<boolean>;
10593
select(): Promise<void>;
10694
toggle(): Promise<void>;
107-
static with(options?: ChipOptionHarnessFilters): HarnessPredicate<MatChipOptionHarness>;
95+
static with<T extends typeof MatChipHarness>(this: T, options?: ChipOptionHarnessFilters): HarnessPredicate<InstanceType<T>>;
10896
}
10997

11098
// @public

tools/public_api_guard/material/chips.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy, A
188188

189189
// @public
190190
export interface MatChipInputEvent {
191-
chipInput?: MatChipInput;
192-
// @deprecated
193-
input: HTMLInputElement;
191+
chipInput: MatChipInput;
194192
value: string;
195193
}
196194

0 commit comments

Comments
 (0)