Skip to content

Commit 1f2ff16

Browse files
authored
refactor(sort): change deprecated APIs for version 10 (#19372)
Cleans up the APIs that were marked as deprecated for v10. BREAKING CHANGES: * The `_focusMonitor` and `_elementRef` parameters in the `MatSortHeader` constructor are now required.
1 parent 5f12539 commit 1f2ff16

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
2222
{
2323
pr: 'https://github.com/angular/components/pull/19379',
2424
changes: ['MatSlider']
25+
},
26+
{
27+
pr: 'https://github.com/angular/components/pull/19372',
28+
changes: ['MatSortHeader']
2529
}
2630
],
2731
[TargetVersion.V9]: [

src/material/sort/sort-header.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,8 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
142142
@Optional() public _sort: MatSort,
143143
@Inject('MAT_SORT_HEADER_COLUMN_DEF') @Optional()
144144
public _columnDef: MatSortHeaderColumnDef,
145-
/**
146-
* @deprecated _focusMonitor and _elementRef to become required parameters.
147-
* @breaking-change 10.0.0
148-
*/
149-
private _focusMonitor?: FocusMonitor,
150-
private _elementRef?: ElementRef<HTMLElement>) {
145+
private _focusMonitor: FocusMonitor,
146+
private _elementRef: ElementRef<HTMLElement>) {
151147
// Note that we use a string token for the `_columnDef`, because the value is provided both by
152148
// `material/table` and `cdk/table` and we can't have the CDK depending on Material,
153149
// and we want to avoid having the sort header depending on the CDK table because
@@ -173,12 +169,10 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
173169
changeDetectorRef.markForCheck();
174170
});
175171

176-
if (_focusMonitor && _elementRef) {
177-
// We use the focus monitor because we also want to style
178-
// things differently based on the focus origin.
179-
_focusMonitor.monitor(_elementRef, true)
180-
.subscribe(origin => this._setIndicatorHintVisible(!!origin));
181-
}
172+
// We use the focus monitor because we also want to style
173+
// things differently based on the focus origin.
174+
_focusMonitor.monitor(_elementRef, true)
175+
.subscribe(origin => this._setIndicatorHintVisible(!!origin));
182176
}
183177

184178
ngOnInit() {
@@ -195,11 +189,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
195189
}
196190

197191
ngOnDestroy() {
198-
// @breaking-change 10.0.0 Remove null check for _focusMonitor and _elementRef.
199-
if (this._focusMonitor && this._elementRef) {
200-
this._focusMonitor.stopMonitoring(this._elementRef);
201-
}
202-
192+
this._focusMonitor.stopMonitoring(this._elementRef);
203193
this._sort.deregister(this);
204194
this._rerenderSubscription.unsubscribe();
205195
}

tools/public_api_guard/material/sort.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ export declare class MatSortHeader extends _MatSortHeaderMixinBase implements Ca
6464
set disableClear(v: boolean);
6565
id: string;
6666
start: 'asc' | 'desc';
67-
constructor(_intl: MatSortHeaderIntl, changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef,
68-
_focusMonitor?: FocusMonitor | undefined, _elementRef?: ElementRef<HTMLElement> | undefined);
67+
constructor(_intl: MatSortHeaderIntl, changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef, _focusMonitor: FocusMonitor, _elementRef: ElementRef<HTMLElement>);
6968
_getAriaSortAttribute(): "ascending" | "descending" | null;
7069
_getArrowDirectionState(): string;
7170
_getArrowViewState(): string;

0 commit comments

Comments
 (0)