Skip to content

Commit 7a4d94b

Browse files
devversionwagnermaciel
authored andcommitted
refactor: remove light-weight token content-child query cast (#20433)
Initially when we added light-weight tokens to our components, the Angular framework was not properly typed to support injection tokens in the view and content queries. We fixed this upstream with angular/angular#37506 and can now remove the workaround/cast since this change is available due to our recent Angular update to a `next` version. (cherry picked from commit 6e957c1)
1 parent bdc5aa3 commit 7a4d94b

File tree

10 files changed

+23
-46
lines changed

10 files changed

+23
-46
lines changed

src/cdk/drag-drop/directives/drag.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,14 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
7272
/** Reference to the underlying drag instance. */
7373
_dragRef: DragRef<CdkDrag<T>>;
7474

75-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
7675
/** Elements that can be used to drag the draggable item. */
77-
@ContentChildren(CDK_DRAG_HANDLE as any, {descendants: true}) _handles: QueryList<CdkDragHandle>;
76+
@ContentChildren(CDK_DRAG_HANDLE, {descendants: true}) _handles: QueryList<CdkDragHandle>;
7877

79-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
8078
/** Element that will be used as a template to create the draggable item's preview. */
81-
@ContentChild(CDK_DRAG_PREVIEW as any) _previewTemplate: CdkDragPreview;
79+
@ContentChild(CDK_DRAG_PREVIEW) _previewTemplate: CdkDragPreview;
8280

83-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
8481
/** Template for placeholder element rendered to show where a draggable would be dropped. */
85-
@ContentChild(CDK_DRAG_PLACEHOLDER as any) _placeholderTemplate: CdkDragPlaceholder;
82+
@ContentChild(CDK_DRAG_PLACEHOLDER) _placeholderTemplate: CdkDragPlaceholder;
8683

8784
/** Arbitrary data to attach to this drag instance. */
8885
@Input('cdkDragData') data: T;

src/material-experimental/mdc-autocomplete/autocomplete.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import {
3838
]
3939
})
4040
export class MatAutocomplete extends _MatAutocompleteBase {
41-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
42-
@ContentChildren(MAT_OPTGROUP as any, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
41+
@ContentChildren(MAT_OPTGROUP, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
4342
@ContentChildren(MatOption, {descendants: true}) options: QueryList<MatOption>;
4443
protected _visibleClass = 'mat-mdc-autocomplete-visible';
4544
protected _hiddenClass = 'mat-mdc-autocomplete-hidden';

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,14 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
232232
/** Subject that emits when the component has been destroyed. */
233233
protected _destroyed = new Subject<void>();
234234

235-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
236235
/** The chip's leading icon. */
237-
@ContentChild(MAT_CHIP_AVATAR as any) leadingIcon: MatChipAvatar;
236+
@ContentChild(MAT_CHIP_AVATAR) leadingIcon: MatChipAvatar;
238237

239-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
240238
/** The chip's trailing icon. */
241-
@ContentChild(MAT_CHIP_TRAILING_ICON as any) trailingIcon: MatChipTrailingIcon;
239+
@ContentChild(MAT_CHIP_TRAILING_ICON) trailingIcon: MatChipTrailingIcon;
242240

243-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
244241
/** The chip's trailing remove icon. */
245-
@ContentChild(MAT_CHIP_REMOVE as any) removeIcon: MatChipRemove;
242+
@ContentChild(MAT_CHIP_REMOVE) removeIcon: MatChipRemove;
246243

247244
/** Reference to the MatRipple instance of the chip. */
248245
@ViewChild(MatRipple) ripple: MatRipple;

src/material-experimental/mdc-form-field/form-field.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
132132
@ContentChild(MatLabel) _labelChildNonStatic: MatLabel|undefined;
133133
@ContentChild(MatLabel, {static: true}) _labelChildStatic: MatLabel|undefined;
134134
@ContentChild(MatFormFieldControl) _formFieldControl: MatFormFieldControl<any>;
135-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
136-
@ContentChildren(MAT_PREFIX as any, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
137-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
138-
@ContentChildren(MAT_SUFFIX as any, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
139-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
140-
@ContentChildren(MAT_ERROR as any, {descendants: true}) _errorChildren: QueryList<MatError>;
135+
@ContentChildren(MAT_PREFIX, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
136+
@ContentChildren(MAT_SUFFIX, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
137+
@ContentChildren(MAT_ERROR, {descendants: true}) _errorChildren: QueryList<MatError>;
141138
@ContentChildren(MatHint, {descendants: true}) _hintChildren: QueryList<MatHint>;
142139

143140
/** Whether the required marker should be hidden. */

src/material/autocomplete/autocomplete.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ export abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase imp
261261
]
262262
})
263263
export class MatAutocomplete extends _MatAutocompleteBase {
264-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
265-
@ContentChildren(MAT_OPTGROUP as any, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
264+
@ContentChildren(MAT_OPTGROUP, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
266265
@ContentChildren(MatOption, {descendants: true}) options: QueryList<MatOption>;
267266
protected _visibleClass = 'mat-autocomplete-visible';
268267
protected _hiddenClass = 'mat-autocomplete-hidden';

src/material/chips/chip.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,14 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
189189
/** Whether the chip list as a whole is disabled. */
190190
_chipListDisabled: boolean = false;
191191

192-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
193192
/** The chip avatar */
194-
@ContentChild(MAT_CHIP_AVATAR as any) avatar: MatChipAvatar;
193+
@ContentChild(MAT_CHIP_AVATAR) avatar: MatChipAvatar;
195194

196-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
197195
/** The chip's trailing icon. */
198-
@ContentChild(MAT_CHIP_TRAILING_ICON as any) trailingIcon: MatChipTrailingIcon;
196+
@ContentChild(MAT_CHIP_TRAILING_ICON) trailingIcon: MatChipTrailingIcon;
199197

200-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
201198
/** The chip's remove toggler. */
202-
@ContentChild(MAT_CHIP_REMOVE as any) removeIcon: MatChipRemove;
199+
@ContentChild(MAT_CHIP_REMOVE) removeIcon: MatChipRemove;
203200

204201
/** Whether the chip is selected. */
205202
@Input()

src/material/form-field/form-field.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,10 @@ export class MatFormField extends _MatFormFieldMixinBase
273273
@ContentChild(MatLabel, {static: true}) _labelChildStatic: MatLabel;
274274
@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;
275275

276-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
277-
@ContentChildren(MAT_ERROR as any, {descendants: true}) _errorChildren: QueryList<MatError>;
278-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
279-
@ContentChildren(_MAT_HINT as any, {descendants: true}) _hintChildren: QueryList<MatHint>;
280-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
281-
@ContentChildren(MAT_PREFIX as any, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
282-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
283-
@ContentChildren(MAT_SUFFIX as any, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
276+
@ContentChildren(MAT_ERROR, {descendants: true}) _errorChildren: QueryList<MatError>;
277+
@ContentChildren(_MAT_HINT, {descendants: true}) _hintChildren: QueryList<MatHint>;
278+
@ContentChildren(MAT_PREFIX, {descendants: true}) _prefixChildren: QueryList<MatPrefix>;
279+
@ContentChildren(MAT_SUFFIX, {descendants: true}) _suffixChildren: QueryList<MatSuffix>;
284280

285281
constructor(
286282
public _elementRef: ElementRef, private _changeDetectorRef: ChangeDetectorRef,

src/material/menu/menu.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,11 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
177177
*/
178178
@ContentChildren(MatMenuItem, {descendants: false}) items: QueryList<MatMenuItem>;
179179

180-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
181180
/**
182181
* Menu content that will be rendered lazily.
183182
* @docs-private
184183
*/
185-
@ContentChild(MAT_MENU_CONTENT as any) lazyContent: MatMenuContent;
184+
@ContentChild(MAT_MENU_CONTENT) lazyContent: MatMenuContent;
186185

187186
/** Whether the menu should overlap its trigger. */
188187
@Input()

src/material/select/select.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,14 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
378378
/** All of the defined select options. */
379379
@ContentChildren(MatOption, {descendants: true}) options: QueryList<MatOption>;
380380

381-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
382381
/** All of the defined groups of options. */
383-
@ContentChildren(MAT_OPTGROUP as any, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
382+
@ContentChildren(MAT_OPTGROUP, {descendants: true}) optionGroups: QueryList<MatOptgroup>;
384383

385384
/** Classes to be passed to the select panel. Supports the same syntax as `ngClass`. */
386385
@Input() panelClass: string|string[]|Set<string>|{[key: string]: any};
387386

388-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
389387
/** User-supplied override of the trigger element. */
390-
@ContentChild(MAT_SELECT_TRIGGER as any) customTrigger: MatSelectTrigger;
388+
@ContentChild(MAT_SELECT_TRIGGER) customTrigger: MatSelectTrigger;
391389

392390
/** Placeholder to be shown if no value has been selected. */
393391
@Input()

src/material/tabs/tab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,16 @@ export const MAT_TAB_GROUP = new InjectionToken<any>('MAT_TAB_GROUP');
5353
exportAs: 'matTab',
5454
})
5555
export class MatTab extends _MatTabMixinBase implements OnInit, CanDisable, OnChanges, OnDestroy {
56-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
5756
/** Content for the tab label given by `<ng-template mat-tab-label>`. */
58-
@ContentChild(MAT_TAB_LABEL as any)
57+
@ContentChild(MAT_TAB_LABEL)
5958
get templateLabel(): MatTabLabel { return this._templateLabel; }
6059
set templateLabel(value: MatTabLabel) { this._setTemplateLabelInput(value); }
6160
protected _templateLabel: MatTabLabel;
6261

63-
// TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available.
6462
/**
6563
* Template provided in the tab content that will be used if present, used to enable lazy-loading
6664
*/
67-
@ContentChild(MAT_TAB_CONTENT as any, {read: TemplateRef, static: true})
65+
@ContentChild(MAT_TAB_CONTENT, {read: TemplateRef, static: true})
6866
_explicitContent: TemplateRef<any>;
6967

7068
/** Template inside the MatTab view that contains an `<ng-content>`. */

0 commit comments

Comments
 (0)