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

Commit

Permalink
fix(input): smart icon support for input, textarea, select
Browse files Browse the repository at this point in the history
Fixes #6977.Closes #6979.
  • Loading branch information
devversion authored and ThomasBurleson committed Feb 4, 2016
1 parent 179dc19 commit 7778a9c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ angular.module('material.components.input', [
* </hljs>
*/
function mdInputContainerDirective($mdTheming, $parse) {

var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'MD-SELECT'];

return {
restrict: 'E',
link: postLink,
Expand All @@ -80,8 +83,8 @@ function mdInputContainerDirective($mdTheming, $parse) {
var next = icons[0].nextElementSibling;
var previous = icons[0].previousElementSibling;

element.addClass(next && next.tagName === 'INPUT' ? 'md-icon-left' :
previous && previous.tagName === 'INPUT' ? 'md-icon-right' : '');
element.addClass(next && INPUT_TAGS.indexOf(next.tagName) != -1 ? 'md-icon-left' :
previous && INPUT_TAGS.indexOf(previous.tagName) != -1 ? 'md-icon-right' : '');
}
// In case there are two icons we apply both icon classes
else if (icons.length == 2) {
Expand Down
44 changes: 44 additions & 0 deletions src/components/input/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,49 @@ describe('md-input-container directive', function() {
);
expect(el.hasClass('md-icon-left md-icon-right')).toBeTruthy();
});

it('should add md-icon-left class when md-icon is before select', function() {
var el = compile(
'<md-input-container>' +
'<md-icon></md-icon>' +
'<md-select ng-model="foo"></md-select>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-left')).toBeTruthy();
});

it('should add md-icon-right class when md-icon is before select', function() {
var el = compile(
'<md-input-container>' +
'<md-select ng-model="foo"></md-select>' +
'<md-icon></md-icon>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-right')).toBeTruthy();
});

it('should add md-icon-left class when md-icon is before textarea', function() {
var el = compile(
'<md-input-container>' +
'<md-icon></md-icon>' +
'<textarea ng-model="foo"></textarea>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-left')).toBeTruthy();
});

it('should add md-icon-right class when md-icon is before textarea', function() {
var el = compile(
'<md-input-container>' +
'<textarea ng-model="foo"></textarea>' +
'<md-icon></md-icon>' +
'</md-input-container>'
);

expect(el.hasClass('md-icon-right')).toBeTruthy();
});
});
});

0 comments on commit 7778a9c

Please sign in to comment.