Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit dab30b3

Browse files
fix(icons): improve use of material-icons style
Improve logic to auto-add `.material-icons` style to **md-icon**. > NOTE: will not auto-add if using any class or ng-class attributes; see demoFontIconsWithLigatures Fixes #3333.
1 parent 7ca139a commit dab30b3

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/components/icon/demoFontIconsWithLigatures/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="preview-glyphs">
1212
<md-icon ng-style="{color: font.color}"
1313
aria-label="{{ font.name }}"
14-
class="step"
14+
class="material-icons step"
1515
ng-class="it.size">
1616
{{ font.name }}
1717
</md-icon>

src/components/icon/iconDirective.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,23 @@ function mdIconDirective($mdIcon, $mdTheming, $mdAria, $interpolate ) {
209209

210210
function prepareForFontIcon () {
211211
if (!scope.svgIcon && !scope.svgSrc) {
212+
212213
if (scope.fontIcon) {
213214
element.addClass('md-font');
214215
element.addClass(scope.fontIcon);
215-
} else {
216+
}
217+
218+
if (scope.fontSet) {
216219
element.addClass($mdIcon.fontSet(scope.fontSet));
217220
}
221+
222+
// For Material Design font icons, the class '.material-icons'
223+
// is auto-added IF a style has not been specified
224+
225+
if (!scope.fontIcon && !scope.fontSet && !angular.isDefined(attr.class)) {
226+
227+
element.addClass('material-icons');
228+
}
218229
}
219230

220231
}

src/components/icon/iconDirective.spec.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('mdIcon directive', function() {
1+
ddescribe('mdIcon directive', function() {
22
var el;
33
var $scope;
44
var $compile;
@@ -11,6 +11,7 @@ describe('mdIcon directive', function() {
1111
}));
1212
afterEach( function() {
1313
$mdIconProvider.defaultFontSet('material-icons');
14+
$mdIconProvider.fontSet('fa', 'fa');
1415
});
1516

1617

@@ -21,6 +22,7 @@ describe('mdIcon directive', function() {
2122
$compile = _$compile_;
2223
}));
2324

25+
2426
describe('using font-icons with deprecated md-font-icon=""', function() {
2527

2628
it('should render correct HTML with md-font-icon value as class', function() {
@@ -64,7 +66,7 @@ describe('mdIcon directive', function() {
6466

6567
expect(el.attr('md-font-icon')).toBe($scope.font.name);
6668
expect(el.hasClass('step')).toBe(true);
67-
expect(el.hasClass('material-icons')).toBe(true);
69+
expect(el.hasClass('material-icons')).toBe(false);
6870
expect(el.attr('aria-label')).toBe($scope.font.name + $scope.font.size);
6971
expect(el.attr('role')).toBe('img');
7072
})
@@ -77,7 +79,7 @@ describe('mdIcon directive', function() {
7779
el = make( '<md-icon class="md-48">face</md-icon>');
7880

7981
expect(el.text()).toEqual('face');
80-
expect(el.hasClass('material-icons')).toBeTruthy();
82+
expect(el.hasClass('material-icons')).toBeFalsy();
8183
expect(el.hasClass('md-48')).toBeTruthy();
8284
});
8385

@@ -90,6 +92,15 @@ describe('mdIcon directive', function() {
9092
expect( clean(el.attr('class')) ).toEqual("fontawesome");
9193
});
9294

95+
96+
it('should render correctly using a md-font-set alias', function() {
97+
el = make( '<md-icon md-font-set="fa" md-font-icon="fa-info"></md-icon>');
98+
99+
expect( clean(el.attr('class')) ).toEqual("md-font fa-info fa");
100+
});
101+
102+
103+
93104
it('should render correctly using md-font-set value as class', function() {
94105

95106
el = make( '<md-icon md-font-set="fontawesome">email</md-icon>');
@@ -101,11 +112,19 @@ describe('mdIcon directive', function() {
101112

102113
describe('using font-icons with classnames', function() {
103114

115+
it('should auto-add the material-icons style', function() {
116+
el = make( '<md-icon>apple</md-icon>');
117+
118+
expect(el.text()).toEqual('apple');
119+
expect(el.hasClass('material-icons')).toBeTruthy();
120+
});
121+
122+
104123
it('should render with icon classname', function() {
105124
el = make( '<md-icon class="custom-cake"></md-icon>');
106125

107126
expect(el.text()).toEqual('');
108-
expect(el.hasClass('material-icons')).toBeTruthy();
127+
expect(el.hasClass('material-icons')).toBeFalsy();
109128
expect(el.hasClass('custom-cake')).toBeTruthy();
110129
});
111130

0 commit comments

Comments
 (0)