Skip to content

Commit 79eab38

Browse files
committed
fix(material/icon): forward fontIcon attribute to element (#25779)
In #24578 we added the ability to set font icons using the `fontIcon` input, however it was never forwarded to the `fontIcon` attribute which means using a data binding won't work. Fixes #25759. (cherry picked from commit d53e53b)
1 parent 512ba8d commit 79eab38

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/material/icon/icon.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ describe('MatIcon', () => {
248248
});
249249

250250
describe('Ligature icons by attribute', () => {
251+
it('should forward the fontIcon attribute', () => {
252+
const fixture = TestBed.createComponent(IconWithLigatureByAttribute);
253+
254+
const testComponent = fixture.componentInstance;
255+
const icon = fixture.debugElement.nativeElement.querySelector('mat-icon');
256+
257+
testComponent.iconName = 'home';
258+
fixture.detectChanges();
259+
expect(icon.getAttribute('fontIcon')).toBe('home');
260+
261+
testComponent.iconName = 'house';
262+
fixture.detectChanges();
263+
expect(icon.getAttribute('fontIcon')).toBe('house');
264+
});
265+
251266
it('should add material-icons and mat-ligature-font class by default', () => {
252267
const fixture = TestBed.createComponent(IconWithLigatureByAttribute);
253268

src/material/icon/icon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const funcIriPattern = /^url\(['"]?#(.*?)['"]?\)$/;
147147
'[attr.data-mat-icon-type]': '_usingFontIcon() ? "font" : "svg"',
148148
'[attr.data-mat-icon-name]': '_svgName || fontIcon',
149149
'[attr.data-mat-icon-namespace]': '_svgNamespace || fontSet',
150+
'[attr.fontIcon]': '_usingFontIcon() ? fontIcon : null',
150151
'[class.mat-icon-inline]': 'inline',
151152
'[class.mat-icon-no-color]': 'color !== "primary" && color !== "accent" && color !== "warn"',
152153
},

0 commit comments

Comments
 (0)