Skip to content

Commit 971553d

Browse files
authored
refactor(chips): remove deprecated APIs for v11 (#20463)
Removes the APIs that were marked for deprecation in v11. I also decided to un-deprecate making the `animationMode` parameters required, because there's no good reason for them to be mandatory. BREAKING CHANGES: * `_changeDetectorRef` and `_document` parameters of the `MatChip` constructor are now required. Also the order of some constructor parameters has changed. * `elementRef` parameter of the `MatChipRemove` constructor is now required.
1 parent 42fb35b commit 971553d

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
100100
changeDetectorRef: ChangeDetectorRef,
101101
elementRef: ElementRef, ngZone: NgZone,
102102
@Optional() dir: Directionality,
103-
// @breaking-change 8.0.0 `animationMode` parameter to become required.
104103
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
105104
super(changeDetectorRef, elementRef, ngZone, dir, animationMode);
106105
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
355355
public _changeDetectorRef: ChangeDetectorRef,
356356
readonly _elementRef: ElementRef, protected _ngZone: NgZone,
357357
@Optional() private _dir: Directionality,
358-
// @breaking-change 8.0.0 `animationMode` parameter to become required.
359358
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
360359
super(_elementRef);
361360
this._chipFoundation = new MDCChipFoundation(this._chipAdapter);

src/material/chips/chip.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,19 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
283283
private _ngZone: NgZone,
284284
platform: Platform,
285285
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS)
286-
globalRippleOptions: RippleGlobalOptions | null,
287-
// @breaking-change 8.0.0 `animationMode` parameter to become required.
286+
globalRippleOptions: RippleGlobalOptions | null,
287+
private _changeDetectorRef: ChangeDetectorRef,
288+
@Inject(DOCUMENT) _document: any,
288289
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string,
289-
// @breaking-change 9.0.0 `_changeDetectorRef` parameter to become required.
290-
private _changeDetectorRef?: ChangeDetectorRef,
291-
@Attribute('tabindex') tabIndex?: string,
292-
// @breaking-change 11.0.0 `_document` parameter to become required.
293-
@Optional() @Inject(DOCUMENT) _document?: any) {
290+
@Attribute('tabindex') tabIndex?: string) {
294291
super(_elementRef);
295292

296293
this._addHostClassName();
297294

298295
// Dynamically create the ripple target, append it within the chip, and use it as the
299296
// chip's ripple target. Adding the class '.mat-chip-ripple' ensures that it will have
300297
// the proper styles.
301-
this._chipRippleTarget = (_document || document).createElement('div');
298+
this._chipRippleTarget = _document.createElement('div');
302299
this._chipRippleTarget.classList.add('mat-chip-ripple');
303300
this._elementRef.nativeElement.appendChild(this._chipRippleTarget);
304301
this._chipRipple = new RippleRenderer(this, _ngZone, this._chipRippleTarget, platform);
@@ -332,7 +329,7 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
332329
if (!this._selected) {
333330
this._selected = true;
334331
this._dispatchSelectionChange();
335-
this._markForCheck();
332+
this._changeDetectorRef.markForCheck();
336333
}
337334
}
338335

@@ -341,7 +338,7 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
341338
if (this._selected) {
342339
this._selected = false;
343340
this._dispatchSelectionChange();
344-
this._markForCheck();
341+
this._changeDetectorRef.markForCheck();
345342
}
346343
}
347344

@@ -350,15 +347,15 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
350347
if (!this._selected) {
351348
this._selected = true;
352349
this._dispatchSelectionChange(true);
353-
this._markForCheck();
350+
this._changeDetectorRef.markForCheck();
354351
}
355352
}
356353

357354
/** Toggles the current selected state of this chip. */
358355
toggleSelected(isUserInput: boolean = false): boolean {
359356
this._selected = !this.selected;
360357
this._dispatchSelectionChange(isUserInput);
361-
this._markForCheck();
358+
this._changeDetectorRef.markForCheck();
362359
return this.selected;
363360
}
364361

@@ -441,13 +438,6 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
441438
});
442439
}
443440

444-
private _markForCheck() {
445-
// @breaking-change 9.0.0 Remove this method once the _changeDetectorRef is a required param.
446-
if (this._changeDetectorRef) {
447-
this._changeDetectorRef.markForCheck();
448-
}
449-
}
450-
451441
static ngAcceptInputType_selected: BooleanInput;
452442
static ngAcceptInputType_selectable: BooleanInput;
453443
static ngAcceptInputType_removable: BooleanInput;
@@ -480,11 +470,8 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
480470
export class MatChipRemove {
481471
constructor(
482472
protected _parentChip: MatChip,
483-
// @breaking-change 11.0.0 `elementRef` parameter to be made required.
484-
elementRef?: ElementRef<HTMLElement>) {
485-
486-
// @breaking-change 11.0.0 Remove null check for `elementRef`.
487-
if (elementRef && elementRef.nativeElement.nodeName === 'BUTTON') {
473+
elementRef: ElementRef<HTMLElement>) {
474+
if (elementRef.nativeElement.nodeName === 'BUTTON') {
488475
elementRef.nativeElement.setAttribute('type', 'button');
489476
}
490477
}

src/material/schematics/ng-update/data/constructor-checks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import {ConstructorChecksUpgradeData, TargetVersion, VersionChanges} from '@angu
1414
* automatically through type checking.
1515
*/
1616
export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
17+
[TargetVersion.V11]: [
18+
{
19+
pr: 'https://github.com/angular/components/issues/20463',
20+
changes: ['MatChip', 'MatChipRemove']
21+
}
22+
],
1723
[TargetVersion.V10]: [
1824
{
1925
pr: 'https://github.com/angular/components/pull/19307',

tools/public_api_guard/material/chips.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export declare class MatChip extends _MatChipMixinBase implements FocusableOptio
3939
trailingIcon: MatChipTrailingIcon;
4040
get value(): any;
4141
set value(value: any);
42-
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, animationMode?: string, _changeDetectorRef?: ChangeDetectorRef | undefined, tabIndex?: string, _document?: any);
42+
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, _changeDetectorRef: ChangeDetectorRef, _document: any, animationMode?: string, tabIndex?: string);
4343
_addHostClassName(): void;
4444
_blur(): void;
4545
_handleClick(event: Event): void;
@@ -58,7 +58,7 @@ export declare class MatChip extends _MatChipMixinBase implements FocusableOptio
5858
static ngAcceptInputType_selected: BooleanInput;
5959
static ngAcceptInputType_tabIndex: NumberInput;
6060
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatChip, "mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]", ["matChip"], { "color": "color"; "disableRipple": "disableRipple"; "tabIndex": "tabIndex"; "selected": "selected"; "value": "value"; "selectable": "selectable"; "disabled": "disabled"; "removable": "removable"; }, { "selectionChange": "selectionChange"; "destroyed": "destroyed"; "removed": "removed"; }, ["avatar", "trailingIcon", "removeIcon"]>;
61-
static ɵfac: i0.ɵɵFactoryDef<MatChip, [null, null, null, { optional: true; }, { optional: true; }, null, { attribute: "tabindex"; }, { optional: true; }]>;
61+
static ɵfac: i0.ɵɵFactoryDef<MatChip, [null, null, null, { optional: true; }, null, null, { optional: true; }, { attribute: "tabindex"; }]>;
6262
}
6363

6464
export declare class MatChipAvatar {
@@ -193,7 +193,7 @@ export declare class MatChipListChange {
193193

194194
export declare class MatChipRemove {
195195
protected _parentChip: MatChip;
196-
constructor(_parentChip: MatChip, elementRef?: ElementRef<HTMLElement>);
196+
constructor(_parentChip: MatChip, elementRef: ElementRef<HTMLElement>);
197197
_handleClick(event: Event): void;
198198
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatChipRemove, "[matChipRemove]", never, {}, {}, never>;
199199
static ɵfac: i0.ɵɵFactoryDef<MatChipRemove, never>;

0 commit comments

Comments
 (0)