Skip to content

refactor(icon): change deprecated APIs for version 10 #19323

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
16 changes: 5 additions & 11 deletions src/material/icon/icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export class MatIconRegistry implements OnDestroy {
@Optional() private _httpClient: HttpClient,
private _sanitizer: DomSanitizer,
@Optional() @Inject(DOCUMENT) document: any,
// @breaking-change 9.0.0 _errorHandler parameter to be made required
@Optional() private readonly _errorHandler?: ErrorHandler) {
private readonly _errorHandler: ErrorHandler) {
this._document = document;
}

Expand Down Expand Up @@ -380,12 +379,7 @@ export class MatIconRegistry implements OnDestroy {
// Swallow errors fetching individual URLs so the
// combined Observable won't necessarily fail.
const errorMessage = `Loading icon set URL: ${url} failed: ${err.message}`;
// @breaking-change 9.0.0 _errorHandler parameter to be made required
if (this._errorHandler) {
this._errorHandler.handleError(new Error(errorMessage));
} else {
console.error(errorMessage);
}
this._errorHandler.handleError(new Error(errorMessage));
return observableOf(null);
})
);
Expand Down Expand Up @@ -641,8 +635,8 @@ export function ICON_REGISTRY_PROVIDER_FACTORY(
parentRegistry: MatIconRegistry,
httpClient: HttpClient,
sanitizer: DomSanitizer,
document?: any,
errorHandler?: ErrorHandler) {
errorHandler: ErrorHandler,
document?: any) {
return parentRegistry || new MatIconRegistry(httpClient, sanitizer, document, errorHandler);
}

Expand All @@ -654,7 +648,7 @@ export const ICON_REGISTRY_PROVIDER = {
[new Optional(), new SkipSelf(), MatIconRegistry],
[new Optional(), HttpClient],
DomSanitizer,
[new Optional(), ErrorHandler],
ErrorHandler,
[new Optional(), DOCUMENT as InjectionToken<any>],
],
useFactory: ICON_REGISTRY_PROVIDER_FACTORY,
Expand Down
30 changes: 8 additions & 22 deletions src/material/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
OnChanges,
OnDestroy,
OnInit,
Optional,
SimpleChanges,
ViewEncapsulation,
} from '@angular/core';
Expand Down Expand Up @@ -185,13 +184,8 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
constructor(
elementRef: ElementRef<HTMLElement>, private _iconRegistry: MatIconRegistry,
@Attribute('aria-hidden') ariaHidden: string,
/**
* @deprecated `location` parameter to be made required.
* @breaking-change 8.0.0
*/
@Optional() @Inject(MAT_ICON_LOCATION) private _location?: MatIconLocation,
// @breaking-change 9.0.0 _errorHandler parameter to be made required
@Optional() private readonly _errorHandler?: ErrorHandler) {
@Inject(MAT_ICON_LOCATION) private _location: MatIconLocation,
private readonly _errorHandler: ErrorHandler) {
super(elementRef);

// If the user has not explicitly set aria-hidden, mark the icon as hidden, as this is
Expand Down Expand Up @@ -240,12 +234,7 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
.pipe(take(1))
.subscribe(svg => this._setSvgElement(svg), (err: Error) => {
const errorMessage = `Error retrieving icon ${namespace}:${iconName}! ${err.message}`;
// @breaking-change 9.0.0 _errorHandler parameter to be made required.
if (this._errorHandler) {
this._errorHandler.handleError(new Error(errorMessage));
} else {
console.error(errorMessage);
}
this._errorHandler.handleError(new Error(errorMessage));
});
} else if (svgIconChanges.previousValue) {
this._clearSvgElement();
Expand All @@ -268,7 +257,7 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft
ngAfterViewChecked() {
const cachedElements = this._elementsWithExternalReferences;

if (cachedElements && this._location && cachedElements.size) {
if (cachedElements && cachedElements.size) {
const newPath = this._location.getPathname();

// We need to check whether the URL has changed on each change detection since
Expand Down Expand Up @@ -310,13 +299,10 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Aft

// Note: we do this fix here, rather than the icon registry, because the
// references have to point to the URL at the time that the icon was created.
if (this._location) {
const path = this._location.getPathname();
this._previousPath = path;
this._cacheChildrenWithExternalReferences(svg);
this._prependPathToReferences(path);
}

const path = this._location.getPathname();
this._previousPath = path;
this._cacheChildrenWithExternalReferences(svg);
this._prependPathToReferences(path);
this._elementRef.nativeElement.appendChild(svg);
}

Expand Down
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 @@ -34,6 +34,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
{
pr: 'https://github.com/angular/components/pull/19363',
changes: ['MatTooltip']
},
{
pr: 'https://github.com/angular/components/pull/19323',
changes: ['MatIcon', 'MatIconRegistry']
}
],
[TargetVersion.V9]: [
Expand Down
13 changes: 6 additions & 7 deletions tools/public_api_guard/material/icon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export declare function getMatIconNoHttpProviderError(): Error;

export declare const ICON_REGISTRY_PROVIDER: {
provide: typeof MatIconRegistry;
deps: (Optional[] | typeof DomSanitizer)[];
deps: (Optional[] | typeof DomSanitizer | typeof ErrorHandler)[];
useFactory: typeof ICON_REGISTRY_PROVIDER_FACTORY;
};

export declare function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry: MatIconRegistry, httpClient: HttpClient, sanitizer: DomSanitizer, document?: any, errorHandler?: ErrorHandler): MatIconRegistry;
export declare function ICON_REGISTRY_PROVIDER_FACTORY(parentRegistry: MatIconRegistry, httpClient: HttpClient, sanitizer: DomSanitizer, errorHandler: ErrorHandler, document?: any): MatIconRegistry;

export interface IconOptions {
viewBox?: string;
Expand All @@ -31,15 +31,14 @@ export declare class MatIcon extends _MatIconMixinBase implements OnChanges, OnI
get inline(): boolean;
set inline(inline: boolean);
svgIcon: string;
constructor(elementRef: ElementRef<HTMLElement>, _iconRegistry: MatIconRegistry, ariaHidden: string,
_location?: MatIconLocation | undefined, _errorHandler?: ErrorHandler | undefined);
constructor(elementRef: ElementRef<HTMLElement>, _iconRegistry: MatIconRegistry, ariaHidden: string, _location: MatIconLocation, _errorHandler: ErrorHandler);
ngAfterViewChecked(): void;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
ngOnInit(): void;
static ngAcceptInputType_inline: BooleanInput;
static ɵcmp: i0.ɵɵComponentDefWithMeta<MatIcon, "mat-icon", ["matIcon"], { "color": "color"; "inline": "inline"; "svgIcon": "svgIcon"; "fontSet": "fontSet"; "fontIcon": "fontIcon"; }, {}, never, ["*"]>;
static ɵfac: i0.ɵɵFactoryDef<MatIcon, [null, null, { attribute: "aria-hidden"; }, { optional: true; }, { optional: true; }]>;
static ɵfac: i0.ɵɵFactoryDef<MatIcon, [null, null, { attribute: "aria-hidden"; }, null, null]>;
}

export interface MatIconLocation {
Expand All @@ -52,7 +51,7 @@ export declare class MatIconModule {
}

export declare class MatIconRegistry implements OnDestroy {
constructor(_httpClient: HttpClient, _sanitizer: DomSanitizer, document: any, _errorHandler?: ErrorHandler | undefined);
constructor(_httpClient: HttpClient, _sanitizer: DomSanitizer, document: any, _errorHandler: ErrorHandler);
addSvgIcon(iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
addSvgIconInNamespace(namespace: string, iconName: string, url: SafeResourceUrl, options?: IconOptions): this;
addSvgIconLiteral(iconName: string, literal: SafeHtml, options?: IconOptions): this;
Expand All @@ -68,6 +67,6 @@ export declare class MatIconRegistry implements OnDestroy {
ngOnDestroy(): void;
registerFontClassAlias(alias: string, className?: string): this;
setDefaultFontSetClass(className: string): this;
static ɵfac: i0.ɵɵFactoryDef<MatIconRegistry, [{ optional: true; }, null, { optional: true; }, { optional: true; }]>;
static ɵfac: i0.ɵɵFactoryDef<MatIconRegistry, [{ optional: true; }, null, { optional: true; }, null]>;
static ɵprov: i0.ɵɵInjectableDef<MatIconRegistry>;
}