Skip to content

Commit 9c70aa3

Browse files
crisbetoandrewseguin
authored andcommitted
refactor(list): constructor breaking changes for 8.0 (#15723)
Applies the breaking changes for material/list for 8.0. BREAKING CHANGES: * `_elementRef` parameter in `MatList` constructor is now required. * `_changeDetectorRef` parameter in `MatListItem` constructor is now required. Also the order of constructor parameters has changed.
1 parent 5388a38 commit 9c70aa3

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

src/lib/list/list.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,23 @@ export class MatList extends _MatListMixinBase implements CanDisableRipple, OnCh
8888
/** Emits when the state of the list changes. */
8989
_stateChanges = new Subject<void>();
9090

91-
/**
92-
* @deprecated _elementRef parameter to be made required.
93-
* @breaking-change 8.0.0
94-
*/
95-
constructor(private _elementRef?: ElementRef<HTMLElement>) {
91+
constructor(private _elementRef: ElementRef<HTMLElement>) {
9692
super();
9793

98-
if (this._getListType() === 'action-list' && _elementRef) {
94+
if (this._getListType() === 'action-list') {
9995
_elementRef.nativeElement.classList.add('mat-action-list');
10096
}
10197
}
10298

10399
_getListType(): 'list' | 'action-list' | null {
104-
const elementRef = this._elementRef;
100+
const nodeName = this._elementRef.nativeElement.nodeName.toLowerCase();
105101

106-
// @breaking-change 8.0.0 Remove null check once _elementRef is a required param.
107-
if (elementRef) {
108-
const nodeName = elementRef.nativeElement.nodeName.toLowerCase();
109-
110-
if (nodeName === 'mat-list') {
111-
return 'list';
112-
}
102+
if (nodeName === 'mat-list') {
103+
return 'list';
104+
}
113105

114-
if (nodeName === 'mat-action-list') {
115-
return 'action-list';
116-
}
106+
if (nodeName === 'mat-action-list') {
107+
return 'action-list';
117108
}
118109

119110
return null;
@@ -185,10 +176,9 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
185176
@ContentChild(MatListIconCssMatStyler, {static: false}) _icon: MatListIconCssMatStyler;
186177

187178
constructor(private _element: ElementRef<HTMLElement>,
179+
_changeDetectorRef: ChangeDetectorRef,
188180
@Optional() navList?: MatNavList,
189-
@Optional() list?: MatList,
190-
// @breaking-change 8.0.0 `_changeDetectorRef` to be made into a required parameter.
191-
_changeDetectorRef?: ChangeDetectorRef) {
181+
@Optional() list?: MatList) {
192182
super();
193183
this._isInteractiveList = !!(navList || (list && list._getListType() === 'action-list'));
194184
this._list = navList || list;
@@ -201,8 +191,7 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
201191
element.setAttribute('type', 'button');
202192
}
203193

204-
// @breaking-change 8.0.0 Remove null check for _changeDetectorRef.
205-
if (this._list && _changeDetectorRef) {
194+
if (this._list) {
206195
// React to changes in the state of the parent list since
207196
// some of the item's properties depend on it (e.g. `disableRipple`).
208197
this._list._stateChanges.pipe(takeUntil(this._destroyed)).subscribe(() => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
3030
{
3131
pr: 'https://github.com/angular/material2/pull/15761',
3232
changes: ['MatSpinner', 'MatProgressSpinner']
33+
},
34+
{
35+
pr: 'https://github.com/angular/material2/pull/15723',
36+
changes: ['MatList', 'MatListItem']
3337
}
3438
],
3539

tools/public_api_guard/lib/list.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export declare const MAT_SELECTION_LIST_VALUE_ACCESSOR: any;
1010

1111
export declare class MatList extends _MatListMixinBase implements CanDisableRipple, OnChanges, OnDestroy {
1212
_stateChanges: Subject<void>;
13-
constructor(_elementRef?: ElementRef<HTMLElement> | undefined);
13+
constructor(_elementRef: ElementRef<HTMLElement>);
1414
_getListType(): 'list' | 'action-list' | null;
1515
ngOnChanges(): void;
1616
ngOnDestroy(): void;
@@ -29,7 +29,7 @@ export declare class MatListItem extends _MatListItemMixinBase implements AfterC
2929
_avatar: MatListAvatarCssMatStyler;
3030
_icon: MatListIconCssMatStyler;
3131
_lines: QueryList<MatLine>;
32-
constructor(_element: ElementRef<HTMLElement>, navList?: MatNavList, list?: MatList, _changeDetectorRef?: ChangeDetectorRef);
32+
constructor(_element: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, navList?: MatNavList, list?: MatList);
3333
_getHostElement(): HTMLElement;
3434
_isRippleDisabled(): boolean;
3535
ngAfterContentInit(): void;

0 commit comments

Comments
 (0)