Skip to content

Commit 39fa928

Browse files
pavel-agarkovjelbourn
authored andcommittedFeb 11, 2019
fix(icon): add notranslate class (#14889)
Prevents translation services (like Google Translate) from translating icon ligatures used in mat-icon.
1 parent 4775043 commit 39fa928

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎src/lib/icon/icon.spec.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ describe('MatIcon', () => {
7676
sanitizer = ds;
7777
}));
7878

79+
it('should include notranslate class by default', () => {
80+
let fixture = TestBed.createComponent(IconWithColor);
81+
82+
const matIconElement = fixture.debugElement.nativeElement.querySelector('mat-icon');
83+
expect(matIconElement.classList.contains('notranslate'))
84+
.toBeTruthy('Expected the mat-icon element to include the notranslate class');
85+
});
86+
7987
it('should apply class based on color attribute', () => {
8088
let fixture = TestBed.createComponent(IconWithColor);
8189

@@ -84,7 +92,8 @@ describe('MatIcon', () => {
8492
testComponent.iconName = 'home';
8593
testComponent.iconColor = 'primary';
8694
fixture.detectChanges();
87-
expect(sortedClassNames(matIconElement)).toEqual(['mat-icon', 'mat-primary', 'material-icons']);
95+
expect(sortedClassNames(matIconElement))
96+
.toEqual(['mat-icon', 'mat-primary', 'material-icons', 'notranslate']);
8897
});
8998

9099
it('should apply a class if there is no color', () => {
@@ -97,7 +106,7 @@ describe('MatIcon', () => {
97106
fixture.detectChanges();
98107

99108
expect(sortedClassNames(matIconElement))
100-
.toEqual(['mat-icon', 'mat-icon-no-color', 'material-icons']);
109+
.toEqual(['mat-icon', 'mat-icon-no-color', 'material-icons', 'notranslate']);
101110
});
102111

103112
it('should mark mat-icon as aria-hidden by default', () => {
@@ -135,7 +144,7 @@ describe('MatIcon', () => {
135144
testComponent.iconName = 'home';
136145
fixture.detectChanges();
137146
expect(sortedClassNames(matIconElement))
138-
.toEqual(['mat-icon', 'mat-icon-no-color', 'material-icons']);
147+
.toEqual(['mat-icon', 'mat-icon-no-color', 'material-icons', 'notranslate']);
139148
});
140149

141150
it('should use alternate icon font if set', () => {
@@ -147,7 +156,8 @@ describe('MatIcon', () => {
147156
const matIconElement = fixture.debugElement.nativeElement.querySelector('mat-icon');
148157
testComponent.iconName = 'home';
149158
fixture.detectChanges();
150-
expect(sortedClassNames(matIconElement)).toEqual(['mat-icon', 'mat-icon-no-color', 'myfont']);
159+
expect(sortedClassNames(matIconElement))
160+
.toEqual(['mat-icon', 'mat-icon-no-color', 'myfont', 'notranslate']);
151161
});
152162
});
153163

@@ -697,19 +707,19 @@ describe('MatIcon', () => {
697707
testComponent.fontIcon = 'house';
698708
fixture.detectChanges();
699709
expect(sortedClassNames(matIconElement))
700-
.toEqual(['font1', 'house', 'mat-icon', 'mat-icon-no-color']);
710+
.toEqual(['font1', 'house', 'mat-icon', 'mat-icon-no-color', 'notranslate']);
701711

702712
testComponent.fontSet = 'f2';
703713
testComponent.fontIcon = 'igloo';
704714
fixture.detectChanges();
705715
expect(sortedClassNames(matIconElement))
706-
.toEqual(['f2', 'igloo', 'mat-icon', 'mat-icon-no-color']);
716+
.toEqual(['f2', 'igloo', 'mat-icon', 'mat-icon-no-color', 'notranslate']);
707717

708718
testComponent.fontSet = 'f3';
709719
testComponent.fontIcon = 'tent';
710720
fixture.detectChanges();
711721
expect(sortedClassNames(matIconElement))
712-
.toEqual(['f3', 'mat-icon', 'mat-icon-no-color', 'tent']);
722+
.toEqual(['f3', 'mat-icon', 'mat-icon-no-color', 'notranslate', 'tent']);
713723
});
714724

715725
it('should handle values with extraneous spaces being passed in to `fontSet`', () => {
@@ -721,15 +731,16 @@ describe('MatIcon', () => {
721731
fixture.detectChanges();
722732
}).not.toThrow();
723733

724-
expect(sortedClassNames(matIconElement)).toEqual(['font', 'mat-icon', 'mat-icon-no-color']);
734+
expect(sortedClassNames(matIconElement))
735+
.toEqual(['font', 'mat-icon', 'mat-icon-no-color', 'notranslate']);
725736

726737
expect(() => {
727738
fixture.componentInstance.fontSet = ' changed';
728739
fixture.detectChanges();
729740
}).not.toThrow();
730741

731742
expect(sortedClassNames(matIconElement))
732-
.toEqual(['changed', 'mat-icon', 'mat-icon-no-color']);
743+
.toEqual(['changed', 'mat-icon', 'mat-icon-no-color', 'notranslate']);
733744
});
734745

735746
it('should handle values with extraneous spaces being passed in to `fontIcon`', () => {
@@ -742,15 +753,15 @@ describe('MatIcon', () => {
742753
}).not.toThrow();
743754

744755
expect(sortedClassNames(matIconElement))
745-
.toEqual(['font', 'mat-icon', 'mat-icon-no-color', 'material-icons']);
756+
.toEqual(['font', 'mat-icon', 'mat-icon-no-color', 'material-icons', 'notranslate']);
746757

747758
expect(() => {
748759
fixture.componentInstance.fontIcon = ' changed';
749760
fixture.detectChanges();
750761
}).not.toThrow();
751762

752763
expect(sortedClassNames(matIconElement))
753-
.toEqual(['changed', 'mat-icon', 'mat-icon-no-color', 'material-icons']);
764+
.toEqual(['changed', 'mat-icon', 'mat-icon-no-color', 'material-icons', 'notranslate']);
754765
});
755766

756767
});

‎src/lib/icon/icon.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const funcIriPattern = /^url\(['"]?#(.*?)['"]?\)$/;
127127
inputs: ['color'],
128128
host: {
129129
'role': 'img',
130-
'class': 'mat-icon',
130+
'class': 'mat-icon notranslate',
131131
'[class.mat-icon-inline]': 'inline',
132132
'[class.mat-icon-no-color]': 'color !== "primary" && color !== "accent" && color !== "warn"',
133133
},

0 commit comments

Comments
 (0)
Please sign in to comment.