@@ -69,6 +69,7 @@ describe('MatIcon', () => {
6969 declarations : [
7070 IconWithColor ,
7171 IconWithLigature ,
72+ IconWithLigatureByAttribute ,
7273 IconWithCustomFontCss ,
7374 IconFromSvgName ,
7475 IconWithAriaHiddenFalse ,
@@ -125,6 +126,7 @@ describe('MatIcon', () => {
125126 fixture . detectChanges ( ) ;
126127 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
127128 'mat-icon' ,
129+ 'mat-ligature-font' ,
128130 'mat-primary' ,
129131 'material-icons' ,
130132 'notranslate' ,
@@ -143,6 +145,7 @@ describe('MatIcon', () => {
143145 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
144146 'mat-icon' ,
145147 'mat-icon-no-color' ,
148+ 'mat-ligature-font' ,
146149 'material-icons' ,
147150 'notranslate' ,
148151 ] ) ;
@@ -179,7 +182,7 @@ describe('MatIcon', () => {
179182 } ) ;
180183
181184 describe ( 'Ligature icons' , ( ) => {
182- it ( 'should add material-icons class by default' , ( ) => {
185+ it ( 'should add material-icons and mat-ligature-font class by default' , ( ) => {
183186 const fixture = TestBed . createComponent ( IconWithLigature ) ;
184187
185188 const testComponent = fixture . componentInstance ;
@@ -189,13 +192,14 @@ describe('MatIcon', () => {
189192 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
190193 'mat-icon' ,
191194 'mat-icon-no-color' ,
195+ 'mat-ligature-font' ,
192196 'material-icons' ,
193197 'notranslate' ,
194198 ] ) ;
195199 } ) ;
196200
197201 it ( 'should use alternate icon font if set' , ( ) => {
198- iconRegistry . setDefaultFontSetClass ( 'myfont' ) ;
202+ iconRegistry . setDefaultFontSetClass ( 'myfont' , 'mat-ligature-font' ) ;
199203
200204 const fixture = TestBed . createComponent ( IconWithLigature ) ;
201205
@@ -206,6 +210,7 @@ describe('MatIcon', () => {
206210 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
207211 'mat-icon' ,
208212 'mat-icon-no-color' ,
213+ 'mat-ligature-font' ,
209214 'myfont' ,
210215 'notranslate' ,
211216 ] ) ;
@@ -223,7 +228,7 @@ describe('MatIcon', () => {
223228 } ) ;
224229
225230 it ( 'should be able to provide multiple alternate icon set classes' , ( ) => {
226- iconRegistry . setDefaultFontSetClass ( 'myfont' , 'myfont-48x48' ) ;
231+ iconRegistry . setDefaultFontSetClass ( 'myfont' , 'mat-ligature-font' , ' myfont-48x48') ;
227232
228233 let fixture = TestBed . createComponent ( IconWithLigature ) ;
229234
@@ -234,6 +239,62 @@ describe('MatIcon', () => {
234239 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
235240 'mat-icon' ,
236241 'mat-icon-no-color' ,
242+ 'mat-ligature-font' ,
243+ 'myfont' ,
244+ 'myfont-48x48' ,
245+ 'notranslate' ,
246+ ] ) ;
247+ } ) ;
248+ } ) ;
249+
250+ describe ( 'Ligature icons by attribute' , ( ) => {
251+ it ( 'should add material-icons and mat-ligature-font class by default' , ( ) => {
252+ const fixture = TestBed . createComponent ( IconWithLigatureByAttribute ) ;
253+
254+ const testComponent = fixture . componentInstance ;
255+ const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
256+ testComponent . iconName = 'home' ;
257+ fixture . detectChanges ( ) ;
258+ expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
259+ 'mat-icon' ,
260+ 'mat-icon-no-color' ,
261+ 'mat-ligature-font' ,
262+ 'material-icons' ,
263+ 'notranslate' ,
264+ ] ) ;
265+ } ) ;
266+
267+ it ( 'should use alternate icon font if set' , ( ) => {
268+ iconRegistry . setDefaultFontSetClass ( 'myfont' , 'mat-ligature-font' ) ;
269+
270+ const fixture = TestBed . createComponent ( IconWithLigatureByAttribute ) ;
271+
272+ const testComponent = fixture . componentInstance ;
273+ const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
274+ testComponent . iconName = 'home' ;
275+ fixture . detectChanges ( ) ;
276+ expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
277+ 'mat-icon' ,
278+ 'mat-icon-no-color' ,
279+ 'mat-ligature-font' ,
280+ 'myfont' ,
281+ 'notranslate' ,
282+ ] ) ;
283+ } ) ;
284+
285+ it ( 'should be able to provide multiple alternate icon set classes' , ( ) => {
286+ iconRegistry . setDefaultFontSetClass ( 'myfont' , 'mat-ligature-font' , 'myfont-48x48' ) ;
287+
288+ let fixture = TestBed . createComponent ( IconWithLigatureByAttribute ) ;
289+
290+ const testComponent = fixture . componentInstance ;
291+ const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
292+ testComponent . iconName = 'home' ;
293+ fixture . detectChanges ( ) ;
294+ expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
295+ 'mat-icon' ,
296+ 'mat-icon-no-color' ,
297+ 'mat-ligature-font' ,
237298 'myfont' ,
238299 'myfont-48x48' ,
239300 'notranslate' ,
@@ -1042,17 +1103,18 @@ describe('MatIcon', () => {
10421103 it ( 'should handle values with extraneous spaces being passed in to `fontIcon`' , ( ) => {
10431104 const fixture = TestBed . createComponent ( IconWithCustomFontCss ) ;
10441105 const matIconElement = fixture . debugElement . nativeElement . querySelector ( 'mat-icon' ) ;
1106+ fixture . componentInstance . fontSet = 'f1' ;
10451107
10461108 expect ( ( ) => {
10471109 fixture . componentInstance . fontIcon = 'font icon' ;
10481110 fixture . detectChanges ( ) ;
10491111 } ) . not . toThrow ( ) ;
10501112
10511113 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
1114+ 'f1' ,
10521115 'font' ,
10531116 'mat-icon' ,
10541117 'mat-icon-no-color' ,
1055- 'material-icons' ,
10561118 'notranslate' ,
10571119 ] ) ;
10581120
@@ -1063,9 +1125,9 @@ describe('MatIcon', () => {
10631125
10641126 expect ( sortedClassNames ( matIconElement ) ) . toEqual ( [
10651127 'changed' ,
1128+ 'f1' ,
10661129 'mat-icon' ,
10671130 'mat-icon-no-color' ,
1068- 'material-icons' ,
10691131 'notranslate' ,
10701132 ] ) ;
10711133 } ) ;
@@ -1311,6 +1373,11 @@ class IconWithLigature {
13111373 iconName = '' ;
13121374}
13131375
1376+ @Component ( { template : `<mat-icon [fontIcon]="iconName"></mat-icon>` } )
1377+ class IconWithLigatureByAttribute {
1378+ iconName = '' ;
1379+ }
1380+
13141381@Component ( { template : `<mat-icon [color]="iconColor">{{iconName}}</mat-icon>` } )
13151382class IconWithColor {
13161383 iconName = '' ;
0 commit comments