Skip to content

refactor(sort): change deprecated APIs for version 10 #19372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/material/schematics/ng-update/data/constructor-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
{
pr: 'https://github.com/angular/components/pull/19379',
changes: ['MatSlider']
},
{
pr: 'https://github.com/angular/components/pull/19372',
changes: ['MatSortHeader']
}
],
[TargetVersion.V9]: [
Expand Down
24 changes: 7 additions & 17 deletions src/material/sort/sort-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
@Optional() public _sort: MatSort,
@Inject('MAT_SORT_HEADER_COLUMN_DEF') @Optional()
public _columnDef: MatSortHeaderColumnDef,
/**
* @deprecated _focusMonitor and _elementRef to become required parameters.
* @breaking-change 10.0.0
*/
private _focusMonitor?: FocusMonitor,
private _elementRef?: ElementRef<HTMLElement>) {
private _focusMonitor: FocusMonitor,
private _elementRef: ElementRef<HTMLElement>) {
// Note that we use a string token for the `_columnDef`, because the value is provided both by
// `material/table` and `cdk/table` and we can't have the CDK depending on Material,
// and we want to avoid having the sort header depending on the CDK table because
Expand All @@ -173,12 +169,10 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
changeDetectorRef.markForCheck();
});

if (_focusMonitor && _elementRef) {
// We use the focus monitor because we also want to style
// things differently based on the focus origin.
_focusMonitor.monitor(_elementRef, true)
.subscribe(origin => this._setIndicatorHintVisible(!!origin));
}
// We use the focus monitor because we also want to style
// things differently based on the focus origin.
_focusMonitor.monitor(_elementRef, true)
.subscribe(origin => this._setIndicatorHintVisible(!!origin));
}

ngOnInit() {
Expand All @@ -195,11 +189,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
}

ngOnDestroy() {
// @breaking-change 10.0.0 Remove null check for _focusMonitor and _elementRef.
if (this._focusMonitor && this._elementRef) {
this._focusMonitor.stopMonitoring(this._elementRef);
}

this._focusMonitor.stopMonitoring(this._elementRef);
this._sort.deregister(this);
this._rerenderSubscription.unsubscribe();
}
Expand Down
3 changes: 1 addition & 2 deletions tools/public_api_guard/material/sort.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export declare class MatSortHeader extends _MatSortHeaderMixinBase implements Ca
set disableClear(v: boolean);
id: string;
start: 'asc' | 'desc';
constructor(_intl: MatSortHeaderIntl, changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef,
_focusMonitor?: FocusMonitor | undefined, _elementRef?: ElementRef<HTMLElement> | undefined);
constructor(_intl: MatSortHeaderIntl, changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef, _focusMonitor: FocusMonitor, _elementRef: ElementRef<HTMLElement>);
_getAriaSortAttribute(): "ascending" | "descending" | null;
_getArrowDirectionState(): string;
_getArrowViewState(): string;
Expand Down