Skip to content

fix(material/icon): forward fontIcon attribute to element #25779

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
Oct 10, 2022
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
15 changes: 15 additions & 0 deletions src/material/icon/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ describe('MatIcon', () => {
});

describe('Ligature icons by attribute', () => {
it('should forward the fontIcon attribute', () => {
const fixture = TestBed.createComponent(IconWithLigatureByAttribute);

const testComponent = fixture.componentInstance;
const icon = fixture.debugElement.nativeElement.querySelector('mat-icon');

testComponent.iconName = 'home';
fixture.detectChanges();
expect(icon.getAttribute('fontIcon')).toBe('home');

testComponent.iconName = 'house';
fixture.detectChanges();
expect(icon.getAttribute('fontIcon')).toBe('house');
});

it('should add material-icons and mat-ligature-font class by default', () => {
const fixture = TestBed.createComponent(IconWithLigatureByAttribute);

Expand Down
1 change: 1 addition & 0 deletions src/material/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const funcIriPattern = /^url\(['"]?#(.*?)['"]?\)$/;
'[attr.data-mat-icon-type]': '_usingFontIcon() ? "font" : "svg"',
'[attr.data-mat-icon-name]': '_svgName || fontIcon',
'[attr.data-mat-icon-namespace]': '_svgNamespace || fontSet',
'[attr.fontIcon]': '_usingFontIcon() ? fontIcon : null',
'[class.mat-icon-inline]': 'inline',
'[class.mat-icon-no-color]': 'color !== "primary" && color !== "accent" && color !== "warn"',
},
Expand Down