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

fix(icon): Fix bug preventing default fontset from being applied #4829

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions src/components/icon/icon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('mdIcon directive', function() {
el = make( '<md-icon md-font-icon="android"></md-icon>');

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

});

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

it('',function() {
it('should apply default fontset "material-icons" when not specified.',function() {
$scope.font = {
name: 'icon-home',
color: "#777",
size: 48
};

el = make('\
<md-icon \
md-font-icon="{{ font.name }}" \
Expand All @@ -56,20 +62,12 @@ describe('mdIcon directive', function() {
</md-icon> \
');

$scope.$apply(function(){
$scope.font = {
name: 'icon-home',
color: "#777",
size: 48
};
});

expect(el.attr('md-font-icon')).toBe($scope.font.name);
expect(el.hasClass('step')).toBe(true);
expect(el.hasClass('material-icons')).toBe(true);
expect(el.attr('aria-label')).toBe($scope.font.name + $scope.font.size);
expect(el.attr('role')).toBe('img');
})
});

});

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

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

});

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

module(function($provide) {
$provide.value('$mdIcon', function $mdIconMock(id) {

function getIcon(id) {
switch(id) {
case 'android' : return '<svg><g id="android"></g></svg>';
case 'cake' : return '<svg><g id="cake"></g></svg>';
case 'android.svg' : return '<svg><g id="android"></g></svg>';
case 'cake.svg' : return '<svg><g id="cake"></g></svg>';
case 'image:android': return '';
}
var $mdIconMock = function(id) {
return {
then: function(fn) {
switch(id) {
case 'android' : fn('<svg><g id="android"></g></svg>');
case 'cake' : fn('<svg><g id="cake"></g></svg>');
case 'android.svg' : fn('<svg><g id="android"></g></svg>');
case 'cake.svg' : fn('<svg><g id="cake"></g></svg>');
case 'image:android': fn('');
}

return $q(function(resolve){
resolve(getIcon(id));
});
});
}
}
};
$mdIconMock.fontSet = function() {
return 'material-icons';
};
$provide.value('$mdIcon', $mdIconMock);
});

inject(function($rootScope, _$compile_, _$q_){
Expand Down
17 changes: 2 additions & 15 deletions src/components/icon/js/iconDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,12 @@ function mdIconDirective($mdIcon, $mdTheming, $mdAria ) {
return false;
}

function prepareForFontIcon () {
function prepareForFontIcon() {
if (!scope.svgIcon && !scope.svgSrc) {

if (scope.fontIcon) {
element.addClass('md-font ' + scope.fontIcon);
}

if (scope.fontSet) {
element.addClass($mdIcon.fontSet(scope.fontSet));
}

if (shouldUseDefaultFontSet()) {
element.addClass($mdIcon.fontSet());
}

}

function shouldUseDefaultFontSet() {
return !scope.fontIcon && !scope.fontSet;
element.addClass($mdIcon.fontSet(scope.fontSet));
}
}
}
Expand Down