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

Commit b24f55f

Browse files
programmistThomasBurleson
authored andcommitted
fix(icon): Fix bug that prevented custom default fontset from being applied.
Fixes #4349. Closes #4829.
1 parent aaa8909 commit b24f55f

File tree

2 files changed

+29
-43
lines changed

2 files changed

+29
-43
lines changed

src/components/icon/icon.spec.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('mdIcon directive', function() {
2929
el = make( '<md-icon md-font-icon="android"></md-icon>');
3030

3131
expect(el.html()).toEqual('');
32-
expect( clean(el.attr('class')) ).toEqual("md-font android");
32+
expect( clean(el.attr('class')) ).toEqual("md-font android material-icons");
3333

3434
});
3535

@@ -47,7 +47,13 @@ describe('mdIcon directive', function() {
4747
expect(el.html()).toEqual('');
4848
});
4949

50-
it('',function() {
50+
it('should apply default fontset "material-icons" when not specified.',function() {
51+
$scope.font = {
52+
name: 'icon-home',
53+
color: "#777",
54+
size: 48
55+
};
56+
5157
el = make('\
5258
<md-icon \
5359
md-font-icon="{{ font.name }}" \
@@ -56,20 +62,12 @@ describe('mdIcon directive', function() {
5662
</md-icon> \
5763
');
5864

59-
$scope.$apply(function(){
60-
$scope.font = {
61-
name: 'icon-home',
62-
color: "#777",
63-
size: 48
64-
};
65-
});
66-
6765
expect(el.attr('md-font-icon')).toBe($scope.font.name);
6866
expect(el.hasClass('step')).toBe(true);
6967
expect(el.hasClass('material-icons')).toBe(true);
7068
expect(el.attr('aria-label')).toBe($scope.font.name + $scope.font.size);
7169
expect(el.attr('role')).toBe('img');
72-
})
70+
});
7371

7472
});
7573

@@ -146,9 +144,9 @@ describe('mdIcon directive', function() {
146144
el = make( '<md-icon></md-icon>');
147145
expect( clean(el.attr('class')) ).toEqual("fa");
148146

149-
el = make( '<md-icon>apple</md-icon>');
147+
el = make( '<md-icon md-font-icon="fa-apple">apple</md-icon>');
150148
expect(el.text()).toEqual('apple');
151-
expect( clean(el.attr('class')) ).toEqual("fa");
149+
expect( clean(el.attr('class')) ).toEqual("md-font fa-apple fa");
152150

153151
});
154152

@@ -175,22 +173,23 @@ describe('mdIcon directive', function() {
175173
var $q;
176174

177175
module(function($provide) {
178-
$provide.value('$mdIcon', function $mdIconMock(id) {
179-
180-
function getIcon(id) {
181-
switch(id) {
182-
case 'android' : return '<svg><g id="android"></g></svg>';
183-
case 'cake' : return '<svg><g id="cake"></g></svg>';
184-
case 'android.svg' : return '<svg><g id="android"></g></svg>';
185-
case 'cake.svg' : return '<svg><g id="cake"></g></svg>';
186-
case 'image:android': return '';
187-
}
176+
var $mdIconMock = function(id) {
177+
return {
178+
then: function(fn) {
179+
switch(id) {
180+
case 'android' : fn('<svg><g id="android"></g></svg>');
181+
case 'cake' : fn('<svg><g id="cake"></g></svg>');
182+
case 'android.svg' : fn('<svg><g id="android"></g></svg>');
183+
case 'cake.svg' : fn('<svg><g id="cake"></g></svg>');
184+
case 'image:android': fn('');
188185
}
189-
190-
return $q(function(resolve){
191-
resolve(getIcon(id));
192-
});
193-
});
186+
}
187+
}
188+
};
189+
$mdIconMock.fontSet = function() {
190+
return 'material-icons';
191+
};
192+
$provide.value('$mdIcon', $mdIconMock);
194193
});
195194

196195
inject(function($rootScope, _$compile_, _$q_){

src/components/icon/js/iconDirective.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,12 @@ function mdIconDirective($mdIcon, $mdTheming, $mdAria ) {
230230
return false;
231231
}
232232

233-
function prepareForFontIcon () {
233+
function prepareForFontIcon() {
234234
if (!scope.svgIcon && !scope.svgSrc) {
235-
236235
if (scope.fontIcon) {
237236
element.addClass('md-font ' + scope.fontIcon);
238237
}
239-
240-
if (scope.fontSet) {
241-
element.addClass($mdIcon.fontSet(scope.fontSet));
242-
}
243-
244-
if (shouldUseDefaultFontSet()) {
245-
element.addClass($mdIcon.fontSet());
246-
}
247-
248-
}
249-
250-
function shouldUseDefaultFontSet() {
251-
return !scope.fontIcon && !scope.fontSet;
238+
element.addClass($mdIcon.fontSet(scope.fontSet));
252239
}
253240
}
254241
}

0 commit comments

Comments
 (0)